File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Dan Bizman
Ranch Hand
Posts: 387
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic