This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Looking for all interfaces implemented, including inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Looking for all interfaces implemented, including inheritance" Watch "Looking for all interfaces implemented, including inheritance" New topic
Author

Looking for all interfaces implemented, including inheritance

Lance Finney
Ranch Hand

Joined: Apr 26, 2001
Posts: 133
Hi. I'm working on some code, and we're looking for all interfaces implemented by a class, including direct implementation, implementation by superclasses, and the parents interfaces of those implemented directly.
That is, assume class A extends class B and implements interface C. Class B implements interface D, which extends E.
We'd like to do a search on interfaces for class A which would return C, D, and E.
A.class.getInterfaces returns only C. Any thoughts?
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
Call getSuperclass() recursively until it returns Object (or null), calling getInterfaces() on each of the superclasses.
Lance Finney
Ranch Hand

Joined: Apr 26, 2001
Posts: 133
I was hoping to avoid recursion
Actually, I found something good: interfaceClass.isAssignableFrom(objectClass).
It got the job done.
 
Don't get me started about those stupid light bulbs.
 
subject: Looking for all interfaces implemented, including inheritance