[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: the benefits of immutability
On Mon, 2003-08-18 at 08:50, Vadim Nasardinov wrote:
>
> The problem is not that you can't add methods safely. The problem is
> that it is too easy to add them unsafely One of the String's stated
> invariants is its guaranteed immutability. The only way to make sure
> this invariant is *never* violated is to prevent subclassing. Thus,
> true immutability also requires finality.
Object.equals() has a number of stated invariants, too (e.g.,
transitivity), but they're documented, anyone who overloads the method
is responsible for following those invariants. Why can't the
immutability of String objects be handled the same way?
--
"Hurd will be out in a year (or two, or next month, who knows),..."
--Linus Torvalds, 5 October 1991
// seth gordon // sethg@ropine.com // http://ropine.com/sethg/cv.html //