I have a Custom Classloader : CustomClassLoader(extends ClassLoader)
I have a class : IntegerPrint
I load my class with my Custom ClassLoader. I was expecting SOPs in the below code to return the same value. But the first SOP prints "sun.misc.Launcher$AppClassLoader@.." & second SOP prints "CustomClassLoader@.."
Why it happens so? Please advise.
public class IntegerPrinterTest { public static void main(String[] args) throws Exception { CustomClassLoader loader = new CustomClassLoader(IntegerPrinterTest.class.getClassLoader()); Class<?> clazz = loader.loadClass("IntegerPrinter"); System.out.println(IntegerPrinter.class.getClassLoader()); System.out.println(clazz.getClassLoader()); } }