Package groovy.transform
Annotation Type ImmutableBase
-
@Documented @Retention(SOURCE) @Target(TYPE) public @interface ImmutableBaseClass annotation used to assist in the creation of immutable classes. Checks on the validity of an immutable class and makes some preliminary changes to the class. Usually used via the@Immutablemeta annotation.Custom property handling:
- The
@ImmutableBaseannotation supports customization using@PropertyOptionswhich allows a custom property handler to be defined. This is most typically used behind the scenes by the@Immutablemeta-annotation but you can also define your own handler. If a custom handler is present, it will determine the code generated for the getters and setters of any property.
- Since:
- 2.5.0
- See Also:
Immutable,ImmutableOptions,MapConstructor,TupleConstructor,PropertyOptions
- The
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleancopyWithIftrue, this adds a methodcopyWithwhich takes a Map of new property values and returns a new instance of the Immutable class with these values set.
-
-
-
Element Detail
-
copyWith
boolean copyWith
Iftrue, this adds a methodcopyWithwhich takes a Map of new property values and returns a new instance of the Immutable class with these values set. Example:
Unknown keys in the map are ignored, and if the values would not change the object, then the original object is returned. If a method called@groovy.transform.Immutable(copyWith = true) class Person { String first, last } def tim = new Person( 'tim', 'yates' ) def alice = tim.copyWith( first:'alice' ) assert tim.first == 'tim' assert alice.first == 'alice'copyWiththat takes a single parameter already exists in the class, then this setting is ignored, and no method is generated.- Default:
- false
-
-