Originally posted by Phil Hopgood:
3. If you can run any code what's the difference between a static initialiser and a no-arg constructor?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Here's an example of an instance initializer which I have used:Originally posted by Rob Prime:
Now as for the need for non-static initializers: I have never used them, nor do I expect to.
Originally posted by Rob Prime:
Now as for the need for non-static initializers: I have never used them, nor do I expect to.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Originally posted by Jelle Klap:
I've hardly ever used non-static init blocks (appropriately) myself, but what about the following scenario:
Steve
Originally posted by Steve Luke:
In cases like that I have always factored the code into a private method that all the constructors call, since it is more clear what is happening:
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Originally posted by Tristan Rouse:
Wow, that's interesting. I was just looking recently at all the ways it is possible to get the RTTI. Using .class seemed weird enough to me considering classes aren't inheriting a .class field from object, only the .getClass() method. So its one of those slight of hand behind the scenes moves.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
ClassLoader.loadClass() has that optional second boolean argument "resolve" which (despite the name) controls whether the loaded class will be initialized or not. Initialization usually happens immediately when a class is loaded, but apparently there are real cases where a class will be loaded but not immediately initialized.
1. What is RTTI? JLS I guess is Java Language Spec?
Steve