Are all primitive wrapper classes in Java immutable objects? String is immutable. What are the other immutable objects?
One odd "wrapper" class is Void
which doesn't have any valid objects, immutable or otherwise. It can only be set to null.
One use for Void
is to mark generic return types with no value. (You can't use primtive types or void
)
e.g.
Callable callable = new Callable() {
public Void call() {
// do something
return null;
}
};
Even though Date
is technically mutable, I would describe it as "immutable by convension". It is generally understood or assumed you wouldn't change a Date object but would replace it to change it like any other immutable object.