Lew said:
Rrr?
Au contraire. I hear (read) the term "immutable class(es)" all the time.
Sure. Just that "one hears it all the time" and "it makes sense and is
true" are different things.
It
means a class that has been designed so that its attribute values are set
exactly once (canonically at construction time) for any given instance.
An instance of an "immutable class" is informally deemed an "immutable object".
I don't even understand what you mean that the conditions of immutability need
not hold for "an 'object' to be immutable".
I didn't say that, I only said that a final class and certain
properties of the methods are not a precondition for immutability of
objects.
It seems that the definition of "immutable" is "fuzzy" after all.
It gets fuzzy as soon as you apply it to the concept "class".
Let me give a simple example.
class Immutable {
final public int intVal;
final public String strVal;
public Immutable(final int initi, final String inits) ...
}
Now, every object with *run time type* Immutable is immutable. Do you
agree?
And yet it's possible to write:
class Mutable<T> extends Immutable {
public T mutateMe;
...
}
According to your definitions, class Immutable is not immutable, since,
for example
Immutable foo = new Mutable<String>()
is an instance of Immutable, but is mutable.
Yet it still holds that a subset of Immutables instances are indeed
immutable, namely those with a *run time type* Immutable. So, in
deciding if something is immutable, one has to find out it's runtime
type and then look at the corresponding class definition to see if
changes are possible. This "something", however, can only be an object.
Thus, I prefer the notion of an immutable object. It is by no means
fuzzy.
Contrast this with the claim that "class Immutable is not immutable
(since it allows subclasses that could be used to create mutable
objects)". What does this claim tell us about the mutablity of objects
with run time type Immutable? Nothing.