Question 5
Back to Exercise
What is the recommended way to compare two enum values?
- A compareTo() == 0 only
- B == (each constant is a single instance) Correct
- C Comparing their names
- D Comparing hashCode()
Correct Answer: Option B
== is also null-safe, unlike calling equals on a null reference.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!