Project: JDT
Bug 186663 [hashcode/equals] generate hashCode/equals thinks Enums have no hashCode/equals
Reported: 2007-05-11 20:55:28 | Status: verified fixed

Build ID: I20070323-1616 Steps To Reproduce: 1. Create an enum (I have them as inner classes which may be a pre-requisite for this bug to surface). Let's call it DbModel.Currency. 2. Create a class someplace else with just 1 field, 'currency', with as type: DbModel.Currency (statically imported). Let's call this class TestClass. 3. Generate hashCode + equals for TestClass (Source menu). Eclipse will complain that the field is 'dangerous' because the type DbModel.Currency does not have a hashCode or equals method. Which is silly, because enums always have hashCode/equals. You can in fact use == to compare them. More information: Aside from the faulty warning, the generated equals code is extremely ugly and needlessly inefficient. enums should be compared to with a straight ==, no null check neccessary. "Currency" had been imported using an import.static statement. Eclipse still reports the full type name (package.parentclass.innerEnumName) though.

Files changed in fix:
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/GenerateHashCodeEqualsAction.java