Cannot reference “X” before supertype constructor has been called, where x is a final variable

前端 未结 6 492
无人及你
无人及你 2020-12-04 11:06

Consider the following Java class declaration:

public class Test {

    private final int defaultValue = 10;
    private int var;

    public Test() {
               


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-04 11:37

    It is because the defaultValue is an member of Test 's instance which is under construction (not yet created)

    If you had it static it were loaded when your class loads by classloaders

提交回复
热议问题