以编程方式检查.class文件是否扩展了特定类 [英] Checking programmatically if a .class file extends particular class

查看:165
本文介绍了以编程方式检查.class文件是否扩展了特定类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我一直在试图解决相当多个小时。在Eclipse插件中,我有一个ArrayList,它包含一些java .class文件的完整路径(作为字符串)。我想做的是检查列表中包含的类是否扩展一个特定的类。我想到解析文件,寻找扩展之后是什么,但是我们在谈论.class文件而不是.java文件。任何其他想法?

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?

谢谢!

推荐答案

使用URLClassLoader加载文件(问题:你需要知道正确的父文件夹和Package + ClassName),并使用正常的java.lang.Class方法检查。

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.

这篇关于以编程方式检查.class文件是否扩展了特定类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆