Package de.bmiag.tapir.data
Annotation Type Immutable
-
@Target(TYPE) public @interface Immutable
By annotating a class withImmutable
an immutable class is generated. The following modifications/additions are done:- The annotated class becomes final
- A private constructor is generated
- The
equals
,hashCode
andtoString
methods are generated - Instances have to be built by calling the
build
or thecopy
method. Usingcopy
provides the possibility to copy an existing instance.
- Optionality: By default all attributes are mandatory. If a mandatory field is not initialized the call of
build
orcopy
throws anIllegalStateException
. By usingOptional
an attribute can be defines as optional. It is not necessary to initialize an optional attribute. - Collections: Currently
List
andSet
are handled. The annotation makes sure that only immutableList
andSet
instances are returned. It delegates this task toImmutableList
/ImmutableSet
Immutable.Include
all the private fields of the included type are copied into the immutable class.There are a couple of additional annotations which influence the annotation processor, please consult the corresponding documentation:
Immutable.Include
,Immutable.ExcludeFromEqualsHashCode
,Immutable.ExcludeFromToString
,Immutable.Modifiable
.- Since:
- 2.0.0
- Author:
- Oliver Libutzki <[email protected]>
- See Also:
Immutable.Include
,Immutable.ExcludeFromEqualsHashCode
,Immutable.ExcludeFromToString
,Immutable.Modifiable
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.Class<?>[]
interfaces
Based on the getters of the specified interfaces fields are generated and the interfaces are implemented.
-
-
-
Element Detail
-
interfaces
java.lang.Class<?>[] interfaces
Based on the getters of the specified interfaces fields are generated and the interfaces are implemented. It is possible to annotate the getters of the interfaces withImmutable.ExcludeFromEqualsHashCode
,Immutable.ExcludeFromToString
orImmutable.Modifiable
which has the same effect as annotating a field of the immutable class.- Returns:
- interfaces to be implemented
- Since:
- 2.0.0
- Default:
- {}
-
-