public String test() {
String s = "a";
try {
new Long("xyz");
} catch (NumberFormatException e) {
s += "a";
return s;
} finally {
s += "a";
}
return s;
}
@Test
public void test2() {
System.out.println(test());
}
输出是aa;try块中的return语句执行成功后,并不马上返回,而是继续执行finally块中的语句,但是返回的还是aa
public String test() {
String s = "a";
try {
new Long("xyz");
} catch (NumberFormatException e) {
s += "a";
return s;
} finally {
s += "a";
return s;
}
}
@Test
public void test2() {
System.out.println(test());
}
输出是aaa;如果此处存在return语句,则在此直接返回。