Java / Design Patterns
In Java singleton, how do you prevent creating instance using reflection?
Create a constructor and throw InstantiationError when the private singleton instance reference is not null.
private Singleton() { if( Singleton.singleton != null ) { throw new InstantiationError( "Creating of this object is not allowed." ); } }
More Related questions...