java - Confusion in class loading styles -
As I have found in a thread that Class.forName () will always use the caller's classloader Class loader .loadClass () can specify a different class loader But the same result above two lines are printing Please tell the reason. There is no difference for you using your existing class SystemClassLoader which was loaded < code> sun.misc.Launcher$AppClassLoader@7ced01 . When you use a different classloader to load a class, both aproaches will use different class loaders used in that category that you have loaded with a different class loader.
System.out.println (Class.ForName ("test.Employee"). GetClassLoader ()); Println (ClassLoader.getSystemClassLoader () loadClass ("test.Employee") getClassLoader () ..);
sun.misc.Launcher$AppClassLoader@7ced01 sun.misc.Launcher $ AppClassLoader @ 7ced01
Comments
Post a Comment