为什么 StringBuilder 不打印应该在小代码中打印的内容
public final class Test1 {
public void test() {
System.out.println(setFin().toString());
}
protected StringBuilder setFin() {
StringBuilder builder = new StringBuilder();
try {
builder.append("John");
return builder.append("Ibrahim");
} finally {
System.out.println("In finaly"); // builder.append("-DarElBeida");
builder = null;
}
}
public static void main(String args[]){
new Test1().test();
}
}
在setFin()
(在finally
块中)执行的最后一条语句中,我已分配null
给builder
,但我的代码打印"In finally"
然后"JohnIbrahim"
. 谁能向我解释这里发生了什么?