Annotation Type Value.Immutable
-
@Documented @Target(TYPE) public static @interface Value.ImmutableInstruct processor to generate immutable implementation of abstract value type. Classes, Interface and Annotation types are supported including top level and non-private static inner types.Annotation has attributes to configure generation of immutable implementation classes, which are usually configured per-type: should the builder (
builder()) be generated or instances interned (intern()). You can useValue.Styleor custom style annotation to tune naming conventions and other settings of code-generation, along with default value for per-type attributes (Value.Style.defaults())Generated accessor methods have annotation copied from original accessor method. However
org.immutables.*andjava.lang.*are not copied. Be warned that such immutable object may contain attributes with types that are not guaranteed to be immutable, thus not every object will be recursively immutable. While this may be useful in some cases, one should generally avoid creating immutable object with attribute values that could be mutated.- See Also:
Value.Style,Value.Include
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleanbuilderIfbuilder=false, disables generation ofbuilder().booleancopyIfcopy=falsethen generation of copying methods will be disabled.booleaninternIfintern=truethen instances will be strong interned on construction.booleanlazyhashIflazyhash=truethen internalhashCodewill be computed (and cached) on firsthashCode()method call.booleanprehashIfprehash=truethenhashCodewill be precomputed during construction.booleansingletonIfsingleton=true, generates internal singleton object constructed without any specified parameters.
-
-
-
Element Detail
-
singleton
boolean singleton
Ifsingleton=true, generates internal singleton object constructed without any specified parameters. Default is false. To access singleton instance use.of()static accessor method.This requires that all attributes have default value (including collections which can be left empty). If some required attributes exist it will result in compilation error. Note that in case object does not have attributes, singleton instance will be generated automatically.
Note that
singleton=truedoes not imply that only one instance of given abstract type. But it does mean that only one "default" instance of the immutable implementation type exist.- Returns:
- if generate singleton default instance
- Default:
- false
-
-
-
copy
boolean copy
Ifcopy=falsethen generation of copying methods will be disabled. This applies to static "copyOf" methods as well as modify-by-copy "withAttributeName" methods which return modified copy using structural sharing where possible. Default value is true, i.e generate copy methods.- Returns:
- if generate copy methods
- Default:
- true
-
-
-
prehash
boolean prehash
Ifprehash=truethenhashCodewill be precomputed during construction. This could speed up map/set lookups for objects with lots of attributes and nested objects. In general, use this whenhashCodecomputation is expensive and will be used a lot. Note that ifValue.Style.privateNoargConstructor()==truethis option will be ignored. For lazy (deferred)hashCodecomputation uselazyhash()- Returns:
- if generate hash code precomputing
- Default:
- false
-
-
-
lazyhash
boolean lazyhash
Iflazyhash=truethen internalhashCodewill be computed (and cached) on firsthashCode()method call. For eagerhashCodecomputation (in constructor) useprehash().- Returns:
- to lazily compute the
hashCode
- Default:
- false
-
-