Checking programmatically if a .class file extends particular class

最后都变了- 提交于 2019-12-11 01:59:25

问题


I have a problem I've been trying to solve for quite some hours. In an Eclipse plugin, I have an ArrayList that contains the full paths (as strings) of some java .class files. What I'd like to do is check if the classes that are included in the list extend a particular class. I thought about parsing the file, looking for what is after "extends," however we are talking about a .class file and not of a .java file. Any other ideas?

Thanks!


回答1:


Use an URLClassLoader to load the file (Problem: You would need to know the right parent folder and Package + ClassName) and use the normal java.lang.Class methods to check.




回答2:


The tool you're looking for is asm. (Or bcel, but asm is more popular these days.)



来源:https://stackoverflow.com/questions/3303484/checking-programmatically-if-a-class-file-extends-particular-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!