This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do you find all subclasses of a given class in Java ?

 
Bijaya Sahoo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a given class or interface how do we find out the list of subclasses or implemented classes ? which is a most convenient way to do this ?
How eclipse quick search (ctrl + T) works to find out the list of subclasses or implemented classes for a given class or interface ?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bijaya Sahoo wrote:For a given class or interface how do we find out the list of subclasses or implemented classes

By using the instanceof operator.
How eclipse quick search (ctrl + T) works to find out the list of subclasses or implemented classes for a given class or interface ?

The IDE is intelligent to gather the information about the classes in its workspace - which extends or implements. Depends on the IDE implementation on what it uses internally.
 
Campbell Ritchie
Sheriff
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

The Oracle/Sun API documentation has a “known subclasses” link, but that will probably not find all the subclasses. It is not a usual requirement of object-orientation that a superclass “know” anything about its subclasses.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class shouldn't know about its sub classes. The reason why you can see the "known subclasses" in the Javadoc pages is because the Javadoc tool loads these classes as well. It doesn't find the sub classes based on a class - it finds the sub classes when going through all the classes, and then just matches them with the super class. That's also why it's called known subclasses - these are only the sub classes that were known when running the Javadoc tool. For example, JPanel has only two known sub classes where there are probably hundreds or thousands around. However, these were not available when the Javadoc tool was running for the Java SE source code.

Eclipse probably does it in a similar way. It checks all the classes available in the JRE and other libraries, and sees which ones extend the current class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic