I know that the new, dup, invokespecial and astore bytecode pattern will invoke the instance initializer meth
is a static method added by javac and called by JVM after class loading. We can see this method in class bytecode with bytecode outline tools. Note that
is added only if a class needs static initilization, e.g
public class Test1 {
static int x = 1;
public static void main(String[] args) throws Exception {
}
}
public class Test2 {
static final int x = 1;
public static void main(String[] args) throws Exception {
}
}
Test1 has
because its field x
needs to be initialized with 1; while Test2 has no
method because its x
is a constant.
It's also interesting to note that Class.forName
has boolen intialize
param which determines if the class should be initialized after loading or not.