[ 
https://issues.apache.org/jira/browse/GROOVY-10919?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17683180#comment-17683180
 ] 

Paul King commented on GROOVY-10919:
------------------------------------

If you are wanting default values and tuple constructors and map-like 
constructors, the now recommended approach to achieve what you are after in 
Groovy 4 is to leave out {{@MapConstructor}} and instead the {{namedVariant}} 
attribute with {{@TupleConstructor}}, i.e. use:
{code}
@TupleConstructor(includeFields = true, namedVariant = true)
{code}


> @MapConstructor Breaks in Groovy4 when combined with @TupleConstructor, fine 
> in Groovy3
> ---------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10919
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10919
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.8
>            Reporter: Aleks Tamarkin
>            Priority: Major
>
> @MapConstructor Breaks in Groovy4 when combined with @TupleConstructor, fine 
> in Groovy3
>  
> Example in Groovy4
> {code:java}
> import groovy.transform.*
> @MapConstructor(includeFields = true)
> @TupleConstructor(includeFields = true)
> @ToString(includeNames = true, includeFields = true)
> class Foo {    
>   private final float w = 1    
>   private final int x    
>   private int y = 1    
>   private final int z
> }
> println new Foo(x:2, z: 3){code}
> outputs the incorrect value
> {code:java}
> Foo(x:2, y:0, z:3){code}
> In Groovy3 it outputs the correct 
> {code:java}
> Foo(x:2, y:1, z:3){code}
> Also commenting out @TupleConstructor in Groovy4 causes the output to be the 
> correct value. 
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to