当我查看binary class file时我可以轻松地找出需要加载哪些其他类才能使用该类吗?
作为一种“目录”,我只能看到带有类条目的常量池表。第一个和第二个条目有特定的含义,直接在我找到的 JVM Spec and elsewhere 中解释。 。但是该表中的其他条目是该类文件使用的其他类的列表吗?可以这么说 *.java
文件的 import
部分的 JVM 变体吗?
所以归结为:
- 常量池表中的所有类条目是否都引用类文件中某处使用的类?
- 或者是否存在其他机制如何让类条目进入常量池?
- 假设我不想在第一次使用类时实现某种“延迟类加载”,那么我是否会通过使用类条目来加载已用类的正确列表 在常量台球 table 中?
最佳答案
Do all Class entries in the constant pool table refer to a class that is used somewhere in the class file?
不,您始终可以放入实际未使用的常量池条目。使用标准编译器编译的类将仅包含实际使用的条目。
Or are there other mechanisms how a Class entry may get into the constant pool?
不,常量池是固定的。尽管磁盘上的文件可能并不代表加载的实际类,因为自定义类加载器或 Java 代理始终可以在运行时操作事物。
Assuming I wold not like to implement some kind of "lazy class loading" on first use of a class, am I therefore loading the correct list of used classes by using the class entries in the constant pool table?
对于静态分析,这是您能做的最好的事情。请注意,您将错过通过反射使用的依赖项,但对此您无能为力。
关于java - 如何从原始类文件中找出依赖的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22555044/