I’m writing a Singleton class in Java EE 6 using the @Singleton annotation. I have not declared a constructor.
Do I have to create a private constructor explicitly?
The reason I’m asking is that I’m using PMD and the rule UseSingleton
is flagged. I think that PMD does not understand the annotation @Singleton?
PMD is recommending making the constructor
privateso that others may not instantiate your singleton object. It’s unaware of Java EE 6 annotations.You can safely ignore this warning.