看一个测试用例:
public class StaticFieldTest {
public static int A= 1;
static {
A=2;
NAME="AAA";
// System.out.println(NAME); // Can't forward reference
}
public static String NAME = "Archer";
public static void main(String[] args) {
System.out.println(NAME);
}
}
输出是Archer
。很明显,这NAME="AAA"
很乏味。为什么 Java 允许这种写法?