Re: what the benefit is by using annotation, like "@Immutable" ?
On 7/16/2010 6:36 PM, Andreas Leitgeb wrote:
Lew<lew@lewscanon.com> wrote:
Object doesn't have attributes, so describing it as "immutable"
runs into a triviality exception.
While not even displayed by javap on java.lang.Object, it actually
does contain a mutable word: the lock.
PS: I think I read that somewhere - or maybe my aunt's neighbour's
...'s ... oh, and jvisualvm seems to hint towards it, too.
But then again, the monitor may not count as a field...
This gets back to Jim Janney's point that there's no truly
solid definition of "immutable" that satisfies every need. If we
say an object is "mutable" if it has observable state (that is,
something that can cause executable code to behave in different
ways at different times), then every Java object is "mutable" in
the sense that its monitor can be held or not held, affecting the
behavior of any executable code that then tries to acquire it. This
encourages us to say things like "Monitors don't count," but then we
start thinking about other things that might not quite satisfy a
plausible definition of "immutable" -- like String's lazily-computed
hash code, for example. And then we get to "If it's not a monitor
and not directly observable from outside, it doesn't count," and the
short word "immutable" starts to disappear behind a veil of caveats,
codicils, and cavils.
The cited net.jcip.annotations.Immutable propounds a definition
of "immutable" that I think reasonable people would term "sufficient,"
but that others would think "not necessary:" Surely any class meeting
the JCIP criteria would be called "immutable," but many classes that
do *not* meet it might well be considered "immutable" by other, equally
reasonable people. For example, Map.Entry does not satisfy the JCIP
notion of "immutable," although *I* (a person I consider reasonable)
would categorize it as such.
"Immutable" means "not mutable." It sounds solid, but I think it
trails off into "Mutable by whom?" and "Mutable in what ways?" and
"What would Werner Heisenberg's cat think?" A squishy, relativistic
notion when you start to probe at it.
--
Eric Sosman
esosman@ieee-dot-org.invalid