• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

Find loaded classes derived from X

Is there a way to enumerate classes which have been loaded, which are derived from X or which implement interface Y?

My best shot is to do something like:

(1) Assume it is Sun J2 and enumerate all classes using the approach shown at http://www.javaworld.com/javaworld/javaqa/2003-07/02-qa-0725-classsrc2.html where you snoop the ClassLoader private Vector of classes.

(2) Use the instanceof operator on each to find the classes.

Is there something less brutal and more efficient? I can live without portability, but that would be nice too.
0
rstaveley
Asked:
rstaveley
  • 2
1 Solution
 
objectsCommented:
that would seem the way to go
0
 
objectsCommented:
may break though if sun changes underlying class loader implementation
0
 
rstaveleyAuthor Commented:
Thanks for verifying.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now