Why doesn't `Lazy` implement `equals` and `hashc...
# stdlib
m
Why doesn't
Lazy
implement
equals
and
hashcode
?
d
What does it mean for two `Lazy`s to be equal?
m
Both are initialized and both values are equal.
this is literally stupid
e
so
==
could change depending on when whether it's been read or not? no, that's terrible.
m
so you are assuming that one should never write equals & hashcode for mutable objects?
d
Yeah I thought that as well. While I don't like the idea of a
==
for
Lazy
, I can't objectively justify it.
e
OK if the mutation is explicit
j
Lazy is a service object which produces a value, not a value object itself. Identity is the correct implementation of equals and hashCode.
5
d
Also, if you have
Lazy<String>
and
Lazy<List<*>>
. If they're both uninitialised, should they be equal? (Note that you can't do runtime type checks)
☝️ 1
e
well, you'll be prevented from writing that
==
just based in static types, usually
but should
lazy { println("a"); 0 } == lazy { println("b"); 0 }
?
👍 1
m
Ok, this sounds convincing.
Thank you for your explanations