Extending a singleton in Java

java, singleton

Solution

You cannot extend a proper Singleton since it's supposed to have a private constructor:

Effective Java Item 2: Enforce the singleton property with a private constructor

Problem

What I'd like to do is just make a class that when you extend it, you automatically get the getInstance class. The problem is, when i extend it, I can't reference the child class. The only way I could see to do it is by typecasting ((ClassName)class.getInstance()) but its not very user-friendly. Any suggestions?

Original source

Related problems