wood burning stoves*
The moose likes Beginning Java and the fly likes How find all subclasses and/or implementing classes of interface? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How find all subclasses and/or implementing classes of interface?" Watch "How find all subclasses and/or implementing classes of interface?" New topic
Author

How find all subclasses and/or implementing classes of interface?

Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
Is there a way to find out all the subclasses in the current VM of a particular class if it's not an interface and all the implementing classes if it is an interface (at runtime)?
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
Is there a way to list all classes available in the class path? If so, you can use reflection to check for each of the classes if they implement a given interface / extend a given (super) class.

However, I'm not exactly sure if there is a way of listing all classes in the class path - afraid there isn't. But you might be able to read the class path and search it for .class files, and also search all the .jar files you find for .class entries. (I do some plugin loading by searching jars for implementations of specific interfaces).

What do you intend to do with the result of your search? Maybe there's a different way of achieving the same functionality.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
It's a very complicated operation. My answer to anyone asking the question at this level would be "no".

More likely you'd want to parse all the jars in the class path without forcing every class to be loaded. I think there have been a library or two written to do that. I'm not sure where they might be.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How find all subclasses and/or implementing classes of interface?