Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Type | Name and Description |
---|---|
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.
|
Class[] |
knownImmutableClasses Allows you to provide @Immutable with a list of classes which
are deemed immutable. |
String[] |
knownImmutables Allows you to provide @Immutable with a list of property names which
are deemed immutable. |
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.
@default false Allows you to provide @Immutable
with a list of classes which
are deemed immutable. By supplying a class in this list, you are vouching
for its immutability and @Immutable
will do no further checks.
Example:
import groovy.transform.*@default {}@Immutable
(knownImmutableClasses = [Address]) class Person { String first, last Address address }@TupleConstructor
class Address { final String street }
Allows you to provide @Immutable
with a list of property names which
are deemed immutable. By supplying a property's name in this list, you are vouching
for its immutability and @Immutable
will do no further checks.
Example:
@groovy.transform.Immutable
(knownImmutables = ['address'])
class Person {
String first, last
Address address
}
...
@default {}