public class StaticTest {
private static String a;
private static String b = "this is " + a;
public static void main(String[] args) {
a = "test";
System.out.println(b); // prints "this is null"
}
}
Ich bin verwirrt über b
Wert. Ich denke, das Ergebnis sollte "das ist Test" sein, aber das Ergebnis ist "das ist Null". Warum?Warum ist dieses statische Java-Feld null?
Statisches Feld wurde während der Klassenlast initialisiert. In diesem Moment war 'a'' null'. – Oleksandr