Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
@Data needs a warning when either equals() or hashCode() is already implemented #548
I was in the process of Lombokifying a bean, step by step. This meant removing the hashCode(), leaving equals() as it was, and counting on Lombok to generate an appropriate hashCode().
It only became clear when, on a whim, we add @ EqualsAndHashCode to our class. This gave us an appropriate warning ("Not generating equals, hashCode and canEquals: A method with one of those names already exists. (Either all or none of these methods will be generated).")
I would like to see the same warning on @ Data.
Side note: I tried using delombok to figure out the issue. However, in order to make my class compile without the whole classpath, I removed equals() temporarily. I saw the code generated by delombok, so I was quite sure that nothing was wrong... Of course, I immediately restore equals() and didn't make the connection with the problem at all. ;-)
This isn't a lombok bug, it's a bug in our specs, because this is dumb but specified behaviour.
We are going to re-spec the behaviour to this new rule: If using @ Data and you have only one of the pair of equals/hashCode methods implemented, you get a warning. If you have 0 of the 2, they get added. If you have both, they aren't, and you get no warning.
That's how it works now except for the weird '1 is there but the other one is missing' case that you ran into.