[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: the benefits of immutability
On 2003.08.22 11:45 Vadim Nasardinov wrote:
> I need a little more convincing that this is indeed the root of the
> problem. Even if Java did have multi-methods, it would just take
> fewer lines of code to write a non-transitive 'equals' method. I'm
> all for shorter code, but that doesn't address the crux of the matter,
> now does it? The crux of the matter is, no matter how smart Jeannette
> is, Barbara's job is *hard*. It is non-trivial to write an externally
> facing class that allows subclassing.
I'm not sure your example proves this. Equality in Java is inherently
non-transitive regardless of subclassing, because if a and b are
objects belonging to different classes then a.equals(b) and b.equals(a)
are in general calls to two separate methods that don't necessarily
have anything to do with each other. As I see it subclassing actually
makes it easier to make equality consistent (by allowing you to put the
implementation in a common superclass), though as your example shows it
certainly doesn't guarantee it.
Apart from the admittedly broken equality model in Java, what precisely
are the difficulties in subclassing an externally facing class?
Michael St. Hippolyte