Is it OK to use ==
on enums in Java, or do I need to use .equals()
? In my testing, ==
always works, but I\'m not sure if I\'m guarant
== compares the references of two objects. For enums, it is guaranteed that there will only be one instance, and therefore for any two enums that are the same, == will be true.
Reference:
http://www.ajaxonomy.com/2007/java/making-the-most-of-java-50-enum-tricks
(couldn't find anything in the Sun docs)