There's a presentation on AutoValue (a terse way to define immutable objects in Java, with sensible defaults for equals
, hashCode
, etc.): https://docs.google.com/presentation/d/14u_h-lMn7f1rXE1nDiLX0azS3IkgjGl5uxp5jGJ75RE/edit#slide=id.g2a5e9c4a8_047
In the beginning, they go over some alternatives to AutoValue. Obviously, one alternative is a POJO coded by hand. They warn about this POJO being unexpectedly hard to change.
I've transcribed the slide here:
Are changes really that risky?
Suppose a required int field becomes optional. You change
int number;
to
Integer number;
Tests still pass... and everything's fine... until one day, objects put into Sets start mysteriously "disappearing" from the set! Why? (Left as an exercise to the reader.)
I can't figure out this "exercise". What kind of "disappearing"? contains(element)
is unexpectedly false
? size()
decrements without remove()
? iterator()
doesn't include the element anymore? And why would any of these happen?