3 ms·
There definitely are cases where that's not enough, but it's a 95-99% solution. The problems you mentioned: Classes could change equals to accept subclasses.
by dtech 8y ago
There definitely are cases where that's not enough, but it's a 95-99% solution.
The problems you mentioned:
Classes could change equals to accept subclasses. Then subclasses could not alter equality themselves.
T implementing `equals(other: U)` for some U solves a lot of other use-cases, but could make equality asymetrical.
Reference equality would still exist, but would not be the default, e.g. Java's `equals` is Scala's `==`, and Java's `==` is Scala's `eq` operator (which you almost never use)
- naasking 8y agohttps://blog.janestreet.com/the-perils-of-polymorphic-compare/ https://blog.janestreet.com/the-perils-of-polymorphic-compar...