Jaroslav Gorshkov
Jaroslav Gorshkov

Reputation: 93

How to find a certain method from classes with the same simple name?

I have many ObjectFactory classes that reside in different packages. They are all standalone classes, meaning that they don't extend from any class. I cannot modify those classes.

Now, I need to provide an ObjectFactory to a command-handler class. This ObjectFactory must have a set of methods needed for this exact command-handler class.

How would I go on about scanning all the ObjectFactory classes from different packages to find one with the methods that I need?

Thank you in advance

Upvotes: 0

Views: 53

Answers (1)

Dakshinamurthy Karra
Dakshinamurthy Karra

Reputation: 5463

The only way I can think of doing this is to read all the classes in the class path. Assuming that you have a specific package prefix - you can reduce the number of classes to scan.

Anyhow, look at reflections. You can get all classes with methods having some specific signature etc. with its help.

Upvotes: 1

Related Questions