问题描述见stackoverflow:
stackoverflow:Cannot reference “X” before supertype constructor has been called, where x is a final variable
看完stackoverflow上的解答后我反而更迷惑了(也有可能有是英语不过关的原因。。。)。因为我知道对象字段加载先于构造器,构造器创建时字段已经存在,那为什么会出现调用错误呢?
链接中得票最高的解答有这么一句:
when an object of type Test is created, a unique instance of defaultValue is also created and attached to that particular object. Because of this, it is not possible to ....
这段话意思是说当对象加载时,字段实例也被加载,就因为这个原因,所以错误。????这话说的好迷,就算这个非常'unique'的字段被加载进了非常'particular'的对象中,那构造器也是后一步才加载的事啊,怎么就能得出错误原因了呢?
红颜莎娜
相关分类