[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: the benefits of immutability
Seth Gordon <sethg@ropine.com> writes:
> 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?
His so-called "reason" doesn't explain why StringBuffer is final, too,
in any case.
--
Perry E. Metzger perry@piermont.com