You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "gekm (Jira)" <ji...@apache.org> on 2020/02/25 14:47:00 UTC

[jira] [Issue Comment Deleted] (GROOVY-9421) Ternary operator in a property assignment

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

gekm updated GROOVY-9421:
-------------------------
    Comment: was deleted

(was: Thank for your answer.
But why do i need to pass null into the setter? It is probably not a default value. 
Moreover i can type any value on it's place and result will not change.)

> Ternary operator in a property assignment
> -----------------------------------------
>
>                 Key: GROOVY-9421
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9421
>             Project: Groovy
>          Issue Type: Bug
>          Components: Groovy Console, groovy-runtime
>    Affects Versions: 2.4.18
>            Reporter: gekm
>            Priority: Major
>
> Why ternary operator in properties works incorrectly with strings?
> {code:groovy}
> class Parent {
>     def String name = (name == null || name == 'somebadname') ? 'default' : name
> }
> a = new Parent()
> println("name is: ${a.name}")
> b = new Parent(name: 'somebadname')
> println("name is: ${b.name}")
> c = new Parent(name: 'other')
> println("name is: ${c.name}")
> {code}
> output:
> {code:java}
> name is: default
> name is: somebadname
> name is: other
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)