Download NetBeans!

20071024 Wednesday October 24, 2007

Untyped Variables in Groovy and the NetBeans Debugger

When I blogged about stepping through Groovy recently (here), Peter Williams left this question in the comments: "Are groovy variables typed and/or can their type change dynamically (e.g. x="foo" followed by x=1 being legal, though the type is changing from string to integer?) If so, is the NetBeans debugger displaying this change properly?"

Well, today I had a look, curious to see what would happen. Here's my Groovy script, with a variable called "thing", which is first defined as "Tom" and then later as "50":

First, once we've stepped past the first definition, the debugger shows us the correct value as well as the type:

Next, it does the same for the number:

Pretty cool. Untyped variables in Groovy are correctly reflected according to type in the NetBeans debugger.

Oct 24 2007, 04:49:44 PM PDT Permalink