Remove additional Groovy record features
Since Groovy 4 record
types are supported like in Java. Out of the
box they already come with additional features, that may or may not be
useful for your current project. So the easy way to disable all of
those features is to just define the record
in a .java
file or under
a source tree, that only the Java compiler sees.
Yet nearly all differences to record
.class
generated with the Java
compiler can be configured. To generate the same result with the Groovy
compiler (or nearly the same: there are some annotations), use the
following annotations for the record
(or make them more easily
available via a groovy.transform.AnnotationCollector
).
@TupleConstructor( // disable map and default-value c'tor defaults = false, // do not generate c'tor versions, that default to null values namedVariant = false // do not generate a c'tor with faux named arguments (AKA map c'tor) ) @RecordOptions( // do not generate additional methods for access to the fields toList = false, // list of fields values toMap = false, // map from field name to value size = false, // amount of defined fields getAt = false // access attributes in definition order by index )