日期:2014-05-20  浏览次数:20685 次

java 中的 non-constant field 指的是哪些字段?
<<深入jvm>>中有这么一段:

The same is not true of interfaces(指接口的第一次初始化与类不同), however. An interface is initialized only because a non-constant field declared by the interface is used

就是不知道这里面的non-constant field 指的是哪些字段?

------解决方案--------------------
从字面看是非常量字段
不过接口中没有非常量字段啊
不明白.
------解决方案--------------------
接口中不能定义non-constant field,应该是书上印错了。关于接口何时初始化,可以看看下面这段代码。

Java code
public class Main {

    public Main(String M) {
        System.out.println(M);
    }
    
    public static void main(String[] args) {
        I1 a = new C2();
        System.out.println("---------");
        Main M = C2.M;
    }
}

interface I1 {
    Main M = new Main("I1");
}

class C1 {
    public static final Main N = new Main("C1");
}

class C2 extends C1 implements I1 {
}