Re: What "singleton class" mean in this example
Friday, June 20, 2003 04:08 AM
1/ In fact you can synchronize on any object! When you use synchronize(anObject), the anObject doesn't have to be (even if it usually is) part of the current method.
2/ Also, a class in Java is an object like any other object. A class is an instance of the class Class. The class Class is the meta-class of all classes. So, Singleton.class is an instance, therefore an object. This object is already existing in the system as it has been created when the class Singleton has been loaded in the VM.
Knowing 1 and 2, you can understand why this code is legal. This doesn't explain if it is clever or not. Actually, it all depends on the definition of your class Singleton. You are the only one to know what it does!