Package groovy.transform
Annotation Type TupleConstructor
-
@Documented @Retention(RUNTIME) @Target(TYPE) public @interface TupleConstructorClass annotation used to assist in the creation of tuple constructors in classes. It allows you to write classes in this shortened form:
The@TupleConstructorclass Customer { String first, last int age Date since Collection favItems } def c1 = new Customer(first:'Tom', last:'Jones', age:21, since:new Date(), favItems:['Books', 'Games']) def c2 = new Customer('Tom', 'Jones', 21, new Date(), ['Books', 'Games']) def c3 = new Customer('Tom', 'Jones')@TupleConstructorannotation instructs the compiler to execute an AST transformation which adds the necessary constructor method to your class. A tuple constructor is created with a parameter for each property (and optionally field and super properties). A default value is provided (using Java's default values) for all parameters in the constructor. Groovy's normal conventions then allows any number of parameters to be left off the end of the parameter list including all of the parameters - giving a no-arg constructor which can be used with the map-style naming conventions. The order of parameters is given by the properties of any super classes with most super first (ifincludeSuperPropertiesis set) followed by the properties of the class followed by the by the fields of the class (ifincludeFieldsis set). Within each grouping the order is as attributes appear within the respective class. Limitations: currently not designed to support inner classes.- Since:
- 1.8.0
- Author:
- Paul King
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleancallSuperShould super properties be called within a call to the parent constructor rather than set as propertiesjava.lang.StringexcludesComma separated list of field and/or property names to exclude from the constructor.booleanforceBy default, this annotation becomes a no-op if you provide your own constructor.booleanincludeFieldsInclude fields in the constructorbooleanincludePropertiesInclude properties in the constructorjava.lang.StringincludesComma separated list of field and/or property names to include within the constructor.booleanincludeSuperFieldsInclude fields from super classes in the constructorbooleanincludeSuperPropertiesInclude properties from super classes in the constructor
-