I like enums for a Singleton but the show stopper is when you need inheritance (as I do here). Enums cannot inherit.
With dp4j a minimal Singleton looks like that:
@com.dp4j.Singleton //(lazy=false)
public class MySingleton extends Parent{}
dp4j will actually create this:
@Singleton
public class ApplicationSingleton extends Parent{
@instance
private static ApplicationSingleton instance = new ApplicationSingleton();
private ApplicationSingleton(){}
@getInstance
public static ApplicationSingleton getInstance(){
return instance;
}
As you point out this solution is vulnerable to a 'Reflection attack'. On dp4j.com there's indeed a demonstration on how to unit test the Singleton using the Reflection API.