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 12:51:00 UTC

[jira] [Created] (GROOVY-9421) Ternary operator in a property assignment

gekm created GROOVY-9421:
----------------------------

             Summary: 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


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)