java - does loadClass() of classLoader loads the class into memory? -


i want create custom class loader. confused loadclass(), method loads specified class memory?

if yes why static block of specified class not invoked?

//main class  package custom_class_loader1;   public class custom_class_loader1 {       public static void main(string[] args) {          try{         customclassloader c=new customclassloader();        class c1= c.loadclass("custom_class_loader1.abc");/**does load abc class memory?**/          }catch(exception e)         {             system.out.println(e);      } } } 

when load class doesn't initalise until used default.

invoking method equivalent invoking loadclass(name, false);

here false means don't resolve class.

one way control use class.forname()

public class main {     public static void main(string[] args) throws classnotfoundexception {         classloader cl = new urlclassloader(new url[0], classloader.getsystemclassloader());         system.out.println("unresolved test");         cl.loadclass("test");         // or         class.forname("test", false, cl);          system.out.println("\ninitialise test");         class.forname("test", true, cl);     } }  class test {     static {         system.out.println("loaded test class");     } } 

prints

unresolved test  initialise test loaded test class 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -