i have following java code:
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.forname("test"); // doesn't work, gives classnotfoundexception //test test = new test(); // works fine } }
why doesn't class.forname("test")
work here while next line works fine?
use outer$nested
(regardless if nested class 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(); } }
Comments
Post a Comment