Warning. Enums are reference types
[comp1110-2I]
Warning. Enums are reference types
[comp1110-2I]In Java, enum values are technically things that reside in memory, like Strings and arrays: each constant such as Month.JANUARY or Month.AUGUST has its own place in memory.
However, for each constant there is exactly one object created by the Java runtime.
This means every time the program refers to Month.JANUARY, it refers to the same object.
Because there is only one instance of each constant, it is safe to compare enum values using ==.
The comparison simply checks whether the two references point to the same object, which correctly tells us whether the two enum values are the same.