why does this output `2` and not `1`?
# getting-started
l
why does this output
2
and not
1
?
t
Because they have different hash codes. You’ll have to override
hashcode()
as well.
👍🏻 1
r
Fascinating, I hadn't looked at the implementation of
List<T>.distinct()
before - under the hood it's doing this:
Copy code
ArrayList(LinkedHashSet(this))
Perfectly reasonable implementation, it's just that naively I wouldn't have expected it to be using a
HashSet
for the deduplication.