我有一个简单的 Java 类,如下所示:
public class Test {
private String s;
public String foo() {
try {
s = "dev";
return s;
}
finally {
s = "override variable s";
System.out.println("Entry in finally Block");
}
}
public static void main(String[] xyz) {
Test obj = new Test();
System.out.println(obj.foo());
}
}
这段代码的输出是这样的:
Entry in finally Block
dev
为什么 s
没有在 finally
块中被覆盖,而是控制打印输出?