top | item 45371942

Nested String Interpolation in Groovy

2 points| 00kevn | 5 months ago |tomisawesome.com

1 comment

order

DecoPerson|5 months ago

The syntax highlighter not understanding GStrings (heh) doesn't help here.

It's obvious once you release that whatever is inside a GString is simply an expression.

    def expr = foo."${baz}"
    println("Bar value: ${expr}")
This makes sense.

But this, or any of the other variations...

    def expr = foo." + baz + "
    println("Bar value: ${expr}")
...does not make sense.

If the syntax highlighter understood GStrings, then this would be obvious.

Let S be string colour and _ be non-string colour:

    println("Bar value: ${foo."${baz}"}")
    ________SSSSSSSSSSSSSS____SSS___SSSS_