5 ms·
> Objects, by contrast, are resistant to this kind of optimization because they have an identity distinct from their value. This is what .equals() tests for: th
by vasvir 3y ago
> Objects, by contrast, are resistant to this kind of optimization because they have an identity distinct from their value. This is what .equals() tests for: the object’s location in memory.
AFAIK equals() test for equality not identity in Java.
- brundolf 3y agoYeah that looked like a typo (the exact opposite of what they meant to say)
- mrkeen 3y ago> AFAIK equals() test for equality not identity in Java. In an ideal world, == would test for equality. In a worse world, equals() would test for equality. But we live in a Java world: Equals() is predefined as an identity check on Objects, and it's up invididual implementations to override that check with something better.
- kaba0 3y agoArguably, equality has no default, meaningful implementation. Object identity is a good default, while data-like objects=records should have the trivial equality in place. But a connection is not equal to any other, even if their internal state is equivalent.
- The_Colonel 3y agoThe default implementation in Object class tests for identity.