I have singleton
public class Singleton
{
private static Singleton instance = new Singleton();
private Singleton()
{
System.out.println("Instance created.");
}
public static Singleton getInstance()
{
return instance;
}
}
I can run this code, but no instance is created unless getInstance()called. This is strange, since mine println()in the constructor should execute, since I am using impatient instance creation.
Can someone explain?
source
share