【发布时间】:2014-03-04 16:52:57
【问题描述】:
我有一个自定义类加载器:CustomClassLoader(extends ClassLoader)
我有一门课:IntegerPrint
我用我的自定义类加载器加载我的类。我期待下面代码中的 SOP 返回相同的值。但第一个 SOP 打印“sun.misc.Launcher$AppClassLoader@..”,第二个 SOP 打印“CustomClassLoader@..”
为什么会这样?请指教。
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());
}
}
【问题讨论】:
标签: java classloader