This 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.
@ImmutableValuefrom any superclass or interface with the annotation.
final, and therefore unalterable once set by the constructor.
ImmutableValueannotated class must also be immutable value types.
@ImmutableValueobjects can be of any type.
Various classes from the Java platform are already immutable, and recognized as such by Pure4J.
Throwable. e.g. checked and unchecked exceptions.
Clients are warned that
hashCode are not pure functions, as they are
not deterministic (being dependent on the system hash code, which is based on object id).
@ImmutableValueannotation will need to implement these.
AbstractImmutableValueis provided as a convenience class, which can be used to reduce boiler-plate code in implementation classes.
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.