aspose file tools*
The moose likes Java in General and the fly likes Reflection and nested classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reflection and nested classes" Watch "Reflection and nested classes" New topic
Author

Reflection and nested classes

Dennis Noren
Greenhorn

Joined: Jan 07, 2005
Posts: 15
Is it possible to write code that uses reflection to get information for nested classes without knowing their names? I'm thinking of nested classes that extend the known superclass. In general, my understanding is that a superclass doesn't "know of" its subclasses, but is this an exception to that? I don't see any of the reflection methods that lead me to believe there is a standard way to get at any nested classes.


Java novice, J2SE 1.4.2<br />Some C, some OOA/OOD
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html getDeclaredClasses()
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html getClasses()

You're right, a superclass never knows about its zero or many subclasses (one of thousands of reasons why a non-final class is an implicit design flaw). You could write an agent using java.lang.instrumentation to maintain a registry of those classes that you're interested in.
[ August 04, 2005: Message edited by: Tony Morris ]

Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reflection and nested classes
 
Similar Threads
reflection
(top level class) vs (a nested top level class)
Inner classes
finding out derived classes
Inheritance Hierarchy??