Disclaimer: Apologies if this question is too basic.
I'm learning about Singleton and have a quick question its implementation, are these differences purely coding preferences or am I missing something?
Singleton Class
public enum SerialNumberGen {
INSTANCE;
private int count;
public synchronized int getNextSerial(){
return count++;
}
Example Implementation
.println(SerialNumberGenerator.INSTANCE.getNextSerial());
My implementation
SerialNumberGen gen = SerialNumberGen.INSTANCE;
System.out.println(gen.getNextSerial());
Is my implementation still adhering to the Singleton pattern? Or is this how Enum classes are supposed to be referenced.
Thanks.