Solved

Find loaded classes derived from X

Posted on 2007-12-05
3
346 Views
Last Modified: 2010-04-21
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
Comment
Question by:rstaveley
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 20415399
that would seem the way to go
0
 
LVL 92

Expert Comment

by:objects
ID: 20415418
may break though if sun changes underlying class loader implementation
0
 
LVL 17

Author Closing Comment

by:rstaveley
ID: 31412954
Thanks for verifying.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question