@RecordBase @RecordOptions @TupleConstructor(namedVariant: true, force: true, defaultsMode: DefaultsMode.AUTO) @PropertyOptions @KnownImmutable @POJO @CompileStatic @AnnotationCollector(mode: AnnotationCollectorMode.PREFER_EXPLICIT_MERGED) @Retention(value: RetentionPolicy.RUNTIME) @Target(value: [ElementType.TYPE]) @Incubating @interface RecordType
Meta annotation used when defining record-like classes.
It allows you to write classes in this shortened form:
@groovy.transform.RecordType
class Cyclist {
String firstName
String lastName
}
def richie = new Cyclist('Richie', 'Porte')
assert richie.toString() =~ /Cyclist.*firstName.*Richie/
The @RecordType
meta-annotation corresponds to adding the following annotations:
RecordBase (which internally piggybacks on @ToString
and @EqualsAndHashCode
),
ImmutableOptions,
PropertyOptions,
CompileStatic,
POJO,
TupleConstructor and
KnownImmutable.
Together these annotations instruct the compiler to execute the necessary transformations to add
the necessary getters, constructors, equals, hashCode and other helper methods that are typically
written when creating record-like classes with the defined properties.
A class created in this way has the following characteristics:
equals
, hashCode
and toString
methods are provided based on the property values.