gpt4 book ai didi

java - resolveClass 不解析符号引用

转载 作者:行者123 更新时间:2023-12-01 23:45:52 26 4
gpt4 key购买 nike

JLS 说resolveClass 方法应该验证所有符号链接(symbolic link)

This specification allows an implementation flexibility as to when linking activities (and, because of recursion, loading) take place, provided that the semantics of the Java programming language are respected, that a class or interface is completely verified and prepared before it is initialized, and that errors detected during linkage are thrown at a point in the program where some action is taken by the program that might require linkage to the class or interface involved in the error.

因此,我尝试创建引用第一个项目中另一个类的类 T,并使用自定义类加载器加载类 T 但不加载另一个引用的类来创建第二个项目。

public class T {
public static AnotherClass field = new AnotherClass();
}
public class AnonClassLoader extends ClassLoader {

public Class findClass(String str) {
byte[] bytes = new byte[0];
try {
bytes = Files.readAllBytes(Paths.get(str));
} catch (IOException e) {
e.printStackTrace();
}
Class<?> aClass = defineClass(null, bytes, 0, bytes.length);
return aClass;
}

public static void main(String[] args) throws IOException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException, InstantiationException, ClassNotFoundException {
AnonClassLoader anonClassLoader = new AnonClassLoader();
Class<?> aClass = anonClassLoader.loadClass("/Users/root/IdeaProjects/untitled/T.class", true);
System.out.println(aClass.getName());
}
}

所以我期望尽快得到NoClassDefFound,但实际结果 - 没有抛出错误,类解析成功

最佳答案

所以,根据错误 ID:JDK-8057777 Cleanup of old and unused VM interfaces热点没有静态解析。

同时,在 hotspot jdk 8原生函数没有实现

关于java - resolveClass 不解析符号引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58240279/

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