You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Jochen Theodorou (JIRA)" <ji...@apache.org> on 2016/03/15 17:59:33 UTC

[jira] [Commented] (GROOVY-7790) Put the value in get method with default value

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

Jochen Theodorou commented on GROOVY-7790:
------------------------------------------

>From the javadoc of this method:{code}
     * Looks up an item in a Map for the given key and returns the value - unless
     * there is no entry for the given key in which case add the default value
     * to the map and return that.
{code}
So it behaves exactly like specified and intended. What is it you find weird? That the map is touched? 

> Put the value in get method with default value 
> -----------------------------------------------
>
>                 Key: GROOVY-7790
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7790
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>            Reporter: Maoxiang Qian
>
> I'm not sure whether it was designed, but it seems to be weird.
> {code:Java}
> groovy> imap=['a':1, 'b':2] 
> groovy> if(imap.get('c',null)==null){ } 
> groovy> imap.each{k, v -> println "${k}:${v}" } 
> a:1
> b:2
> c:null
> Result: [a:1, b:2, c:null]{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)