Reputation: 332
I would like to get the list of child classes which extends a particular parent class.For example: - Consider the following case where Class B extends class A and Class C extends class B. I would like to know which are the class that have extended Class A directly or indirectly
Class A
{
/* with some method and parametres
*/
}
Class B extends A
{
/* with some method and parametres
*/
}
Class C extends B
{
/* with some method and parametres
*/
}
I would to get the list of child class name from a java code. i.e I need to write a java class which can give me the list of child classes when I give the name of parent class as Input.
Thanks in advance.
Upvotes: 3
Views: 2143
Reputation: 41210
This is not possible in code without scanning your entire classpath, Java just doesn't store that information. Even then you only know about the references in libraries that you happen to scan.
Within IDEs most have tools to find all classes (using an internal index or database that they have built by scanning all the classes). For example in Eclipse press F4.
Upvotes: 3