I'm new to Java and Groovy, and this is a really simple question on debugging groovy code in groovysh step by step.
$ groovysh
groovy:000> String str = "abcd"
===> abcd
groovy:000> println str
Unknown property: str
In interactives debug shell for all other languages, I was able to define a variable and use it in all the following steps. How to do that as well in groovysh?
As defined in the
groovyshdocumentation page, by default all variables are untyped and thus usingdefor specific type identifier (likeString) does not work. In this case, the proper syntax is juststr = "abcd".As you can see in the example above, you can list all variables that are registered in the shell session with the
:S variablescommand. (You can list all available commands with:hexecuted in the shell window.)However, there is a way to turn on typed variables. This is called the interpreted mode and it can be activated with
:= interpretedModecommand like in the example below: