Is there some way through the standard library or some already existing library to determine the degree of relation between two classes/interfaces in Java?
Let’s say I have an object and a list of classes/interfaces. Now I basically want to know the one class of that list, that has the shortest inheritance-tree path to this object.
I already looked through the java.lang.reflect package and Class, but couldn’t really find anything that would allow easy access to information like this. Is that perhaps already part of another library?
I don’t know anything ready to use.
I would use Reflection to discover the relationships.
The hard part is the shortest-path.
You have to define what exactly you want :
Use alphabetical order ?
Use the order of discovery (which is random) ? …
Then, look for these classes or interfaces in that order, starting with the current class, then it’s parent class (and possibly implemented interfaces), and so on…