Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Java 中 getClass().getClassLoader() 如何返回 null?
jar 中所有类的 ClassLoader 为空。
从文档...
public ClassLoader getClassLoader()
返回类的类加载器。一些实现可能使用 null 来表示引导类加载器。如果此类由引导类加载器加载,则此方法将在此类实现中返回 null。 ... 如果此对象表示原始类型或 void,则返回 null。
返回类的类加载器。一些实现可能使用 null 来表示引导类加载器。如果此类由引导类加载器加载,则此方法将在此类实现中返回 null。
...
如果此对象表示原始类型或 void,则返回 null。
您是否使用任何认可的标准?我相信这会导致类被引导类加载器加载,即使您可能没有明确使用 -Xbootclasspath。