Dlaczego StringBuilder nie drukuje co należy wydrukować w małym kodDlaczego StringBuilder nie drukuje?
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();
}
}
W ostatniej instrukcji wykonywanych w setFin()
(w bloku finally
) Mam przydzielony null
do builder
, ale moje odciski kod "In finally"
a następnie "JohnIbrahim"
. Czy ktoś może mi wyjaśnić, co tu się dzieje?
To jest okropny kod. Prawdopodobnie po prostu chcesz przeczytać http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html – nes1983