[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: the benefits of immutability
On Tuesday, August 19, 2003 8:37 AM, Perry E. Metzger
[SMTP:perry@piermont.com] wrote:
>
> Vadim Nasardinov <el-vadimo@comcast.net> writes:
> > Perry E. Metzger wrote:
> > > His so-called "reason" doesn't explain why StringBuffer is
final,
> > > too, in any case.
> >
> > That is correct. I have not made any comments on why StringBuffer
> > is
> > final. What would be the relevance of such a discussion to the
> > issue
> > at hand?
>
> You explicitly claimed that String was final so that strings could be
> immutable. You then carefully ignored it when it was pointed out
> StringBuffer is final, and yet is mutable.
I believe that Vadim was claiming that *if* java.lang.String were not
final, *then* one could not guarantee that all objects of type
java.lang.String were immutable.
That is, either a class is final or it cannot be guaranteed to be
immutable.
An example of a class that is final *and* mutable is not a
counterexample, for it certainly satisfies the disjunction "final or
not guaranteed immutable".
A counterexample would consist of a class that was both "not final" and
"guaranteed to be immutable". StringBuffer does appear largely
irrelevant, here.