Looking for all interfaces implemented, including inheritance
Lance Finney
Ranch Hand
Joined: Apr 26, 2001
Posts: 133
posted
0
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
posted
0
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
posted
0
I was hoping to avoid recursion Actually, I found something good: interfaceClass.isAssignableFrom(objectClass). It got the job done.