You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2019/11/22 16:58:00 UTC

[jira] [Resolved] (GROOVY-9214) A map's "withDefault" feature is not surviving when supplied to a constructor of @Immutable class

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

Eric Milles resolved GROOVY-9214.
---------------------------------
    Resolution: Not A Problem

The immutable constructor makes a defensive copy so that modification cannot occur due to side effects.

> 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
(v8.3.4#803005)