[ 
https://issues.apache.org/jira/browse/GROOVY-9214?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Phaninra updated GROOVY-9214:
-----------------------------
    Description: 
{code:java}
import groovy.transform.Immutable

Map map = [hi: 1, hello:2].withDefault{3}

assert map.get('does not exist') == 3

Person p = new Person(map: map)

assert p.map.get('does not exist') == 3

@Immutable
class Person{
 Map map
}
{code}
-------------------Update

Sorry for a false alarm - not sure what's the protocol here.

I believe this is due to the constructor changes for Immutable classes. Could 
you please share if there's any documentation on how constructor rules have 
changed from 2.4.x to 2.5.x. The changes don't seem to be backword compatible.

 

For those interested, `new Person(map: map)` is creating a new map and setting 
that as the person.map.  Print out the Person object to understand better.

 

 

 

 

 

  was:
{code:java}
import groovy.transform.Immutable

Map map = [hi: 1, hello:2].withDefault{3}

assert map.get('does not exist') == 3

Person p = new Person(map: map)

assert p.map.get('does not exist') == 3

@Immutable
class Person{
 Map map
}
{code}


> A map's "withDefault" feature is not surviving when supplied to a constructor 
> of @Immutable class
> -------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9214
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9214
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.7
>            Reporter: Phaninra
>            Priority: Major
>
> {code:java}
> import groovy.transform.Immutable
> Map map = [hi: 1, hello:2].withDefault{3}
> assert map.get('does not exist') == 3
> Person p = new Person(map: map)
> assert p.map.get('does not exist') == 3
> @Immutable
> class Person{
>  Map map
> }
> {code}
> -------------------Update
> Sorry for a false alarm - not sure what's the protocol here.
> I believe this is due to the constructor changes for Immutable classes. Could 
> you please share if there's any documentation on how constructor rules have 
> changed from 2.4.x to 2.5.x. The changes don't seem to be backword compatible.
>  
> For those interested, `new Person(map: map)` is creating a new map and 
> setting that as the person.map.  Print out the Person object to understand 
> better.
>  
>  
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to