gpt4 book ai didi

java - getClass().getClassLoader() 为空,为什么?

转载 作者:IT老高 更新时间:2023-10-28 20:53:50 28 4
gpt4 key购买 nike

我有一些代码可以调用..

x = getClass().getClassLoader();

这会返回 null。

当我不是从 Eclipse 而是从命令行启动相同的代码时,它会返回一个类加载器。

我可以破解代码来做到这一点......

if (getClass().getClassLoader() == null)
{
x = ClassLoader.getSystemClassLoader().getSystemResourceAsStream( loadedPropFileName );
}

两者都使用相同的 JVM 编译和运行。 (我有 99.99% 的把握)。

有人知道为什么第一个会为类加载器返回 null 吗?

编辑:

我的问题是“任何人都知道为什么同一个类在通过 Eclipse 启动时会返回 null,而在从命令行加载时会返回类加载器。”

感谢 Bootstap 加载器必须在 Eclipse 中加载类的建议。我不知道为什么会这样。

最佳答案

引用API doc :

Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader.

关于java - getClass().getClassLoader() 为空,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1921238/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com