When there is a final static variable which is not initialized either inline or in a static initializer block, as shown in the example below, the compiler throws an error : "variable x not initialized in the default constructor" .
From this error, it is difficult to make out the actual cause of the error. The above error makes sense in the case of non-static variable, because it can be initialized in the default constructor if not initialized inline. It should be made more relevant, user-friendly and easily understandable in case of static final variables.
public class TestFinalVar {
final static int x;
public static void main(String[] args) {
}
}
From this error, it is difficult to make out the actual cause of the error. The above error makes sense in the case of non-static variable, because it can be initialized in the default constructor if not initialized inline. It should be made more relevant, user-friendly and easily understandable in case of static final variables.
public class TestFinalVar {
final static int x;
public static void main(String[] args) {
}
}