gpt4 book ai didi

java - getClassloader失败原因?

转载 作者:行者123 更新时间:2023-12-01 09:00:57 24 4
gpt4 key购买 nike

只是好奇下面的行什么时候会失败?

this.getClass().getClassLoader();

类加载器总会被找到,对吗?有没有找不到ClassLoader的情况?

最佳答案

看一下源代码。当存在 SecurityManager 并且您无权访问它时,此方法仅抛出 SecurityException。

public ClassLoader getClassLoader() {
ClassLoader cl = getClassLoader0();
if (cl == null)
return null;
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ClassLoader.checkClassLoaderPermission(cl, Reflection.getCallerClass());
}
return cl;
}

如果您想知道 cl 可能是 null。这是一个answer .

关于java - getClassloader失败原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41669287/

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