why static block in child class does not get executed?

前端 未结 5 726
难免孤独
难免孤独 2020-12-19 21:38

here is the code

public class ClassResolution {
static class Parent {
    public static String name;
    static {
        System.out.println(\"this is Parent         


        
5条回答
  •  醉酒成梦
    2020-12-19 22:12

    Oops, I was wrong, the reference to Child was not removed and the class was really loaded, but not initialized. Congratulations, you have found a JVM bug. Go to Oracle site and file it. Let me know if you don't want to do so, I'll do it myself.

    EDIT: I was wrong again, see comment below. This is not a bug, this is a "gotcha".

提交回复
热议问题