8
|
A classic singleton also has a static getInstance() method - call that via reflection instead of using newInstance(). Yeah, it's more work, but that's how it is...
Or you could use setAccessible() to call the private constructor anyway, but you'd break the singleton and go to hell.
Thirdly, you could avoid having a Singleton altogether and find a better soltion (there usually is).
| ||||
3
|
You could use reflection to get a reference to a static factory method of the class, and then invoke that. The factory method could enforce the singleton pattern
And then
Warning: Singleton design pattern may be detrimental to your longterm health.
|