How find all subclasses and/or implementing classes of interface?
Joined: Feb 25, 2003
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)?
Joined: Dec 22, 2004
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.
Joined: Nov 08, 2007
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);
subject: How find all subclasses and/or implementing classes of interface?