• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Looking for all interfaces implemented, including inheritance

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was hoping to avoid recursion
Actually, I found something good: interfaceClass.isAssignableFrom(objectClass).
It got the job done.
reply
    Bookmark Topic Watch Topic
  • New Topic