aspose file tools*
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 Spring in Action this week in the Spring 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looking for all interfaces implemented, including inheritance