Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Looking for all interfaces implemented, including inheritance

 
Lance Finney
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call getSuperclass() recursively until it returns Object (or null), calling getInterfaces() on each of the superclasses.
 
Lance Finney
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was hoping to avoid recursion
Actually, I found something good: interfaceClass.isAssignableFrom(objectClass).
It got the job done.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic