Search code examples
groovygroovyshellgroovy-console

Why groovyConsole supports `def name = "Neo"` while groovysh does not


Following is 2 lines of code:

def name = "Neo"
println name

If I execute it in groovysh, I will get Unknown property: name error. If I execute it in groovyConsole, everything goes on well.


Solution

  • If you want features from Groovy 2.4.0 you can use

    :set interpreterMode true to see a difference. :)

    groovy:000> def a = 10
    ===> 10
    groovy:000> a
    Unknown property: a
    groovy:000> :set interpreterMode true
    groovy:000> a
    Unknown property: a
    groovy:000> def b = 100
    ===> 100
    groovy:000> b
    ===> 100
    groovy:000>