@ImmutableValue
SpecificationThis annotation declares that instances of this class are immutable and are value objects.
That is, In object-oriented and functional programming:
This class declares the immutability contract, which is then checked by the JPure compile-time checker.
@ImmutableValue
from any superclass or interface with the annotation. final
, and therefore unalterable once set by the constructor.final
ImmutableValue
annotated class must also be immutable value types.@ImmutableValue
objects can be of any type.Various classes from the Java platform are already immutable, and recognized as such by Pure4J.
String
s.int
and Integer
@ImmutableValue
. Throwable
. e.g. checked and unchecked exceptions.toString()
and HashCode()
Clients are warned that toString
and hashCode
are not pure functions, as they are
not deterministic (being dependent on the system hash code, which is based on object id).
@ImmutableValue
annotation will need to implement these.AbstractImmutableValue
is provided as a convenience class, which can be used to reduce boiler-plate code
in implementation classes.equals()
equals()
by default is pure.
Your code is expected to observe the contract of equals()
and not modify the state of the parameter object
being passed to it. Unfortunately, this case is not checked by the system.
Exceptions are regarded as being immutable for convenience only. You should not use exceptions for passing system state.
Pure4J will check code in your code base, but assume that anything tagged @ImmutableValue
in a library has been correctly verified
by the build process of that library.