Listing all the subclasses of a specific class in Java

0 votes

How do I list down all the subclasses of a specific class or all the implementers of a specific interface in Java? Using Eclipse, I am able to do so but I want to know how to perform this programmatically? If you have any suggestions, please do put them.

Jun 7, 2018 in Java by code.reaper12
• 3,450 points
128 views

1 answer to this question.

0 votes

There is a simple library available for this purpose: org.reflections

This will scan your classpath, index the metadata, allow you to query it on runtime and may save and collect that information for many modules within your project.

Using Reflections you can query your metadata such as:

  • get all subtypes of some type

  • get all types/constructors/methods/fields annotated with some annotation, optionally with annotation parameters matching

  • get all resources matching a regular expression

  • get all methods with specific signature including parameters, parameter annotations, and return type

  • get all methods parameter names

  • get all fields/methods/constructors usages in code

You just need to call the following to fulfill your task:

reflections.getSubTypesOf(aClazz))

answered Jun 7, 2018 by geek.erkami
• 2,320 points

Related Questions In Java

0 votes
1 answer

Get all the permutations of a string in Java

This is the recursive way of finding a ...READ MORE

answered May 10, 2018 in Java by sharth
• 3,320 points
72 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,840 points
587 views
0 votes
2 answers

Include all the jars in a directory within the Java classpath

Just use lib/*   not lib/*.jar   That's the ...READ MORE

answered Apr 6 in Java by anonymous
1,783 views
0 votes
2 answers

What is the use of final class in java?

In Java, items with the final modifier cannot be ...READ MORE

answered Oct 5, 2018 in Java by Daisy
• 8,040 points
36 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,380 points

edited Nov 6, 2018 by Omkar 6,220 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
1,638 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
4,345 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
338 views
0 votes
1 answer

Why the main() method in Java is always static?

As you might know, static here is ...READ MORE

answered May 8, 2018 in Java by geek.erkami
• 2,320 points
264 views
0 votes
1 answer

Fetch list of in-between dates using Java

I tried generating the list of the ...READ MORE

answered May 10, 2018 in Java by geek.erkami
• 2,320 points
52 views