58 ms·
Yes and: toString() and clone(). Further: default implementations should be synthesized by the runtime. Prevents subtle bugs when the equals(...) and hashCode(
by specialist 4y ago
Yes and: toString() and clone().
Further: default implementations should be synthesized by the runtime. Prevents subtle bugs when the equals(...) and hashCode() implementations are incorrect or missing. eg contract for HashMap.
To backfill, perhaps Object could extend new base class NakedObject, and implement your new interfaces Equalable, Hashable. Then classes which don't need identity can extend NakedObject.
Maybe the "canonical Object" was motivated by prior experience with Self or some such. It definitely calmed down people new to Java & OOP. I think it was the right call at the time.
- kaba0 4y agoRecords are very useful for data-only objects though, as they do implement proper equals and hash.