Top Description Methods
groovy.transform

public @Interface ImmutableBase

extends Annotation
Annotations
@Documented
@Retention:SOURCE
@Target:TYPE
@GroovyASTTransformationClass:ImmutableASTTransformation
Imports
org.codehaus.groovy.transform.GroovyASTTransformationClass, java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target

Class 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 @Immutable meta annotation.

Custom property handling:

Since
2.5.0
See Also
Immutable, ImmutableOptions, MapConstructor, TupleConstructor, PropertyOptions

Method Summary

Modifier and TypeMethod and Description
public boolean
copyWith()

If true, this adds a method copyWith which takes a Map of new property values and returns a new instance of the Immutable class with these values set.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

copyWithback to summary
public boolean copyWith()

If true, this adds a method copyWith which takes a Map of new property values and returns a new instance of the Immutable class with these values set. Example:

@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'
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 copyWith that takes a single parameter already exists in the class, then this setting is ignored, and no method is generated.