The normal (non-lazy) pattern for a singleton is:all IODH does is to put the instance in a Holder class, viz:the assurance you speak of is that the Holder class will not be instantiated until it's required; and since that doesn't occur until you call instanceOf(), it works just fine.
That said, these things are often called anti-patterns for a reason. Their use is extremely rare; and if you can find another way of doing it you probably should. The only reasons that I can think of for using it are:
1. If the object itself takes a prohibitively long time to instantiate.
2. The object takes up an awful lot of space. I have used it myself for this reason to allow for use in resource-limited situations such as MIDP and CLDC (of course, you then have to provide an alternative).
Isn't it funny how there's always time and money enough to do it WRONG?
Joined: Dec 17, 2009
The problem I have is in understanding when the instantiation will occur.
In the non-lazy loading example ..
When will the Singleton class get loaded, will it load before I refer to the static variable 'theOne' ... ?