Friday, October 12, 2007

Use == for Enum comparision

I was recently running FindBugs over some Java5 based code and found some places where FindBugs was complaining that two Objects compared with equals() are not of the same type.
Closer inspection showed that this have been Enums in most cases. The IDEs did not warn here and maunal code inspection also does not directly show the issue.
Luckily with enums, you can use == to compare them. And then it gets obvious:




Just a small little change in habits, but it helps a lot.

No comments: