?
Solved

Find loaded classes derived from X

Posted on 2007-12-05
3
Medium Priority
?
380 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 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