File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to determine class type in static initialization block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to determine class type in static initialization block" Watch "How to determine class type in static initialization block" New topic
Author

How to determine class type in static initialization block

Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
Is there a way to determine the class type, i.e. retrieve a Class object for the class being loade, in static initialization block? I want to use reflection to determine if my subclasses have certain capabilities. I know the proper way to do this would be to use interfaces but, for backwards compatibility, that is not possible at this time.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

During static initialization, the subclasses of your class can't be loaded yet; a class can't be loaded until its parent is.


[Jess in Action][AskingGoodQuestions]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
In fact, a class doesn't know anything about its subclasses, and gets loaded once, not matter how many subclasses exist.

Can you tell us more about what you are trying to achieve?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to determine class type in static initialization block
 
Similar Threads
compilation
static keyword over a block
forward reference question
enum question
Core Java