0

Does eclipse have a feature to automatically generate a singleton of the class upon creating a new class?

As it does for implementing abstract methods of the master class you have defined in the create new class dialog box, can you make it so a class is created like this:

package org.desk.game.model.player.skill;


public final class SkillConfig {

    /**
     * The singleton.
     */
    private static final SkillConfig skillConfig = new SkillConfig();

    /**
     * Get the singleton instance of this class.
     * 
     * @return the singleton.
     */
    public static SkillConfig getInstance() {
        return skillConfig;
    }

    /**
     * Default private constructor to prevent instantiation by other classes.
     */
    private SkillConfig() {

    }
}
kay
  • 321
  • 2
  • 12
  • 1
    It does have that function. You simply use "new Enum" and are done with it. Why? Because it's advised to implement a Singleton as an enum in Java. Compare [here](https://stackoverflow.com/questions/26285520/implementing-singleton-with-an-enum-in-java). – Ben Jul 11 '18 at 10:33
  • 1
    Moreover, [singletons are evil](https://blogs.msdn.microsoft.com/scottdensmore/2004/05/25/why-singletons-are-evil/). Use dependency injection. – maaartinus Jul 11 '18 at 22:45

0 Answers0