Reputation: 33
I would like to get all the classes or interfaces that implements or extends the Externalizable interface. For the same I used
Externalizable.class.isAssignableFrom(clasz)
But my intention is to get only the classes or interfaces that implements or extends Externalizable. I do not need clasz if Externalizable is not a superclass or superinterface of at the first level. It would be great if someone could help me with a solution.
Upvotes: 0
Views: 52
Reputation: 5569
Sounds like you want only classes and interfaces which directly implement Externalizable
.
Class<?>[] interfaces = clasz.getInterfaces();
for (Class<?> c: interfaces) {
if (c.equals(Externalizable.class)) {
// clasz is a direct descendent of Externalizable
}
}
If you just need to know the implementors in Java standard edition, they're listed in the Externalizable javadoc.
Upvotes: 1