我有以下示例
public class Tester
{
/**
* @param args
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws ClassNotFoundException
{
new Tester().execute();
}
private void execute() throws ClassNotFoundException
{
//Java Class Loader
ClassLoader baseClassLoader = Thread.currentThread().getContextClassLoader();
//Java custom Class Loader
ClassLoader customClassLoader = new CustomClassLoader();
Class<?> customClass = Class.forName("a.b.c.d.class", true, customClassLoader);
//Java custom Class Loader
ClassLoader customClassLoader = customClass.getClassLoader();
Thread.currentThread().setContextClassLoader(customClassLoader);
//Java custom Class Loader
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
//Java Class Loader?????
ClassLoader classLoader = this.getClass().getClassLoader();
}
}
为什么调用后
Thread.currentThread().setContextClassLoader(customClassLoader);
一旦我执行
this.getClass().getClassLoader();
我仍然得到 java 类加载器,而不是我的自定义类加载器。
我怎么能做到这一点?
谢谢