如何一个人去尝试找到一个给定类(或给定接口的所有实现)的所有子类在Java? 到目前为止,我有一个方法来做到这一点,但我觉得它效率很低(至少说)。 方法是:
How does one go about and try to find all subclasses of a given class (or all implementors of a given interface) in Java? As of now, I have a method to do this, but I find it quite inefficient (to say the least). The method is:
<有一个很好的功能称为类型层次结构,设法显示这相当有效。
In Eclipse, there is a nice feature called the Type Hierarchy that manages to show this quite efficiently. How does one go about and do it programmatically?
推荐答案没有其他方法可以做到除了什么你描述。想想吧 - 怎么可能有人知道什么类扩展ClassX没有扫描类路径上的每个类?
There is no other way to do it other than what you described. Think about it - how can anyone know what classes extend ClassX without scanning each class on the classpath?
Eclipse只能告诉你关于超类和子类似乎一个有效的时间量,因为它已经在您按下显示在类型层次结构按钮(因为它不断地编译您的类,知道类路径上的一切,等等)加载的所有类型的数据。
Eclipse can only tell you about the super and subclasses in what seems to be an "efficient" amount of time because it already has all of the type data loaded at the point where you press the "Display in Type Hierarchy" button (since it is constantly compiling your classes, knows about everything on the classpath, etc).
更多推荐
如何在Java中找到给定类的所有子类?
发布评论