This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes How do you find all subclasses of a given class in Java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "How do you find all subclasses of a given class in Java ?" Watch "How do you find all subclasses of a given class in Java ?" New topic
Author

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

Bijaya Sahoo
Greenhorn

Joined: Jul 30, 2008
Posts: 1
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
Bartender

Joined: May 31, 2011
Posts: 1776
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

Joined: Oct 13, 2005
Posts: 39044
    
  23
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

Joined: Oct 27, 2005
Posts: 19697
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: How do you find all subclasses of a given class in Java ?