欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

内部静态类的实例化

程序员文章站 2022-07-14 13:09:15
...
public class CheckInnerStatic {

    private static class Test {
    static {
        System.out.println("Static block initialized");
    }
    public Test () {
        System.out.println("Constructor called");
    }
}

    public static void main (String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        System.out.println("Inside main");
        Class<?> cls = Class.forName("CheckInnerStatic$Test");
        //Test test = new Test();
    }
}
今天使用一个类中包含多个内部静态类方式,但实例化时报错,google搜了下正确的使用方法
http://*.com/questions/5828884/loading-static-inner-class-in-java