的請看下面的例子:訂單字段初始化
public class Constructor
{
Constructor(int i)
{
System.out.println(i);
}
}
public class Test
{
Constructor c1 = new Constructor(1);
Constructor c2 = new Constructor(2);
public static void main(String[] args)
{
new Test();
}
}
此輸出:
1
2
請解釋爲什麼發生這種情況,以及是否這種行爲是一致的。
http://stackoverflow.com/questions/804589/use-of-initializers-vs-constructors-in-java –
閱讀合適的手冊:http://docs.oracle.com/javase /specs/jls/se8/html/jls-12.html#jls-12.5 –
真正的問題是什麼? – Adam