Why StringBuilder does not print what it should print in a small code
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();
}
}
In the last statement executed in setFin() (in the finally block) I have assigned null to builder, but my code prints "In finally" and then "JohnIbrahim". Can anybody explain to me what is going on here?