Enums are a shorthand

by: Ethan McCue
public enum StopLight {
    RED, GREEN, YELLOW;
}

Enums are a shorthand for this pattern

public final class StopLight {
    public static final StopLight RED = new StopLight();
    public static final StopLight GREEN = new StopLight();
    public static final StopLight YELLOW = new StopLight();

    private StopLight() {}
}

They get more support by being a language feature just like records but this is it.

So when you say make a singleton like this

public class PlayerManager {
    private static final PlayerManager INSTANCE = new PlayerManager();
    public static PlayerManager getInstance() {
        return INSTANCE;
    }
  
    private PlayerManager() {}
}

all I see is this

public enum PlayerManager {
    INSTANCE;

    public static PlayerManager getInstance() {
        return INSTANCE;
    }
}

<- Index