class B
{
public int i=0;
}
public class MyTestCase {
@Test
public void hello() {
int a = getI();
System.out.println("a = " + a);
B b1 = getB1();
System.out.println("b1.i = " + b1.i);
B b2 = getB2();
System.out.println("b2.i = " + b2.i);
}
private int getI() {
int a = 0;
try {
a = 1;
return a;
} finally {
a = 2;
}
}
private B getB1() {
B b = new B();
try {
b.i = 1;
return b;
} finally {
b.i = 2;
}
}
private B getB2() {
B b = new B();
try {
b.i = 1;
return b;
} finally {
b = new B();
}
}
}
输出:
a = 1
b1.i = 2
b2.i = 1