Java Class.forName默认使用什么类加载器?
我的印象是Java Class.forName默认使用什么类加载器?,java,classloader,Java,Classloader,我的印象是Class.forName(String className)使用Thread.currentThread().getContextClassLoader()加载类,但显然不是这样 因此我的问题是,默认情况下,Class.forName使用什么类加载器?是不是ClassLoader.getSystemClassLoader() Thread.currentThread().getContextClassLoader()和ClassLoader.getSystemClassLoader(
Class.forName(String className)
使用Thread.currentThread().getContextClassLoader()
加载类,但显然不是这样
因此我的问题是,默认情况下,Class.forName
使用什么类加载器?是不是ClassLoader.getSystemClassLoader()
Thread.currentThread().getContextClassLoader()
和ClassLoader.getSystemClassLoader()
之间有什么区别?它使用调用方的类加载器。发件人:
返回与具有给定字符串名称的类或接口关联的类对象。调用此方法相当于:
Class.forName(className, true, currentLoader)
其中currentLoader表示当前类的定义类加载器
它使用调用方的类加载器。发件人: 返回与具有给定字符串名称的类或接口关联的类对象。调用此方法相当于:
Class.forName(className, true, currentLoader)
其中currentLoader表示当前类的定义类加载器
它使用调用器类加载器。forName()的源代码,: 该方法的描述如下:
// Returns the invoker's class loader, or null if none.
它使用调用器类加载器。forName()的源代码,: 该方法的描述如下:
// Returns the invoker's class loader, or null if none.
你的意思是这两个都不是?除非这个类是从其中一个加载的?@AdelBoutros:没错。这是加载调用类的内容。你的意思是它们都不是?除非这个类是从其中一个加载的?@AdelBoutros:没错。这是加载调用类的内容。