2

I want to set @EqualsAndHashCode to avoid verbal code in java. However I want to use default hashCode from Java.

Is it possible using some parameter?

Note: @EqualsAndHashCode belongs to Lombok library who is very used in Java to avoid use getters, setters, constructor , etc.

maaartinus
  • 44,714
  • 32
  • 161
  • 320
Sérgio Thiago Mendonça
  • 1,161
  • 2
  • 13
  • 23
  • In case you understand "hashCode from Java" the inherited `Object#hashCode`, then you'd do very wrong. Any `HashMap` using your object as key would break because of the inconsistency between `hashCode` and `equals`. What Lombok generates is pretty good and you'd better stick with it, unless you know exactly what you're doing. – maaartinus Jul 08 '19 at 22:22

1 Answers1

2

No. It is not possible. There are good reasons why you should implement both. Lombok is doing you a favour by preventing you from doing that.

If want to override just one of them, you'll need to implement it yourself.

Michael
  • 41,989
  • 11
  • 82
  • 128