[ https://issues.apache.org/jira/browse/GROOVY-7427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15147968#comment-15147968 ]
Paul King commented on GROOVY-7427: ----------------------------------- Hi @Chris, it doesn't represent any kind of breaking change, so we could backport it with probably no impact. > TupleConstructor should allow a mechanism to switch off automatic parameter > defaults > ------------------------------------------------------------------------------------ > > Key: GROOVY-7427 > URL: https://issues.apache.org/jira/browse/GROOVY-7427 > Project: Groovy > Issue Type: Improvement > Reporter: Paul King > Assignee: Paul King > Priority: Minor > Fix For: 2.5.0-beta-1 > > > When using @TupleConstructor, it automatically provides defaults for the > parameters. This is particularly useful behavior since it allows parameters > which can remain as their default (user provided or null/0/false) can be left > out of the constructor. In particular, a no-arg constructor corresponds to > the case of all arguments left out. This is exactly the kind of constructor > which Groovy needs for default named-argument processing. > Having said that, there are times when all is required is a single simple > constructor having all of the classes properties. This issue allows a > parameter {{defaults=false}} to be set to enable this new behavior. > For this class: > {code} > @TupleConstructor > class Person { > String first, last > int age > } > {code} > The following normal constructor is produced: > {code} > Person(String first=null, String last=null, int age=0) { this.first = first > //etc... } > {code} > After Groovy's compilation phases are complete, the following constructors > are visible to Java: > {code} > Person(String first, String last, int age) { //... } > Person(String first, String last) { this(first, last, 0) } > Person(String first) { this(first, null) } > Person() { this(null) } > {code} > Adding {{defaults=false}} as a parameter to TupleConstructor means that just > the first of these will be produced. If any of the properties has a default > value, when this setting is made false, an error will be flagged. -- This message was sent by Atlassian JIRA (v6.3.4#6332)