Image

Imagejohnnyopsu wrote in Imagejava_dev

Finding all Implementors of an Interface

I am not an expert in the use of the Reflection API, but I have a gut feeling that something like this might be possible, though I haven't been able to figure out a simple way of doing it.


Is it possible to discover, at runtime, all the concrete classes that implement a given interface?


I have an interface, lets call it Estimator, that I want other people in the company to implement. These other people know a lot more about estimating than I do, and they all have their own code that estimates the given values. What I want is for them to implement an estimator, that the GUI can use. So, at runtime, I want to show people a list of all the known estimators, along with their results.


I know I could do this by keeping a list somewhere of the known implementors, but that is cludgy. I would rather than every implementation in the classpath just show up "magically" in the list.