I was reading about static initializer and came across this question
Why reference to a static final field will not trigger class loading?
I made a little modification of the class from that question:
public class Constants {
public static final String c1;
static {
c1 = "C1";
System.out.println("Constants Class Loaded!");
}
}
Now it is printing:
Constants Class Loaded!
C1
It seems that when I am assigning value to the static final variable in static initializer block the static initializer is run. But it should not run because JLS says referring to constant static variables should not load class. Can anyone give an explanation?