I have the following java code:
public class CheckInnerStatic {
private static class Test {
static {
System.out.println(\"Static block initializ
Use Outer$Nested
(regardless if nested class is static or not)
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();
}
}
You need to use the fully qualified class name, i.e. yourpackage.CheckInnerStatic$Test
(assuming you defined a package, otherwise skip that part).
Class innerClass = Class.forName("com.foo.OuterClass$InnerClass");