我试图理解下面两行之间的区别。为什么当我向字段添加静态时它返回零。
private static final int this_year = Calendar.getInstance().get(Calendar.YEAR);
从这里我得到:this_year = 0;
private final int this_year = Calendar.getInstance().get(Calendar.YEAR);
从这里我得到:this_year = 2013;
谁能解释为什么第一个返回零?
这是我使用它的代码:
public class TheKing {
public static final TheKing theKing = new TheKing();
private final int beltSize;
private static final int this_year = Calendar.getInstance().get(Calendar.YEAR);
private TheKing() {
beltSize = this_year - 1930;
}
public int beltSize() {
return beltSize;
}
public static void main(String[] args) {
System.out.println("TheKing wears a size " +
theKing.beltSize() + " belt.");
}
}