Why this groovy code is marked as invalid?

Hi All,

Why this groovy code is marked as invalid:

new Thread() {
    println "this is a test"

I see a wave line just after "println" and says

';', ',' or new line expected


I'm using idea 9.0.3 community version.

Leo Jay

Comment actions Permalink

Hello Leo,

What version of Groovy are you using?
This code is invalid since Groovy 1.7. Groovy expects anonymous class body after '{' instead of closure.

Comment actions Permalink

I'm using Groovy 1.6.1

Comment actions Permalink

Sorry, but this syntax is obsolete and is not supported by neither newer groovy compilers nor IDEA 9.0.3.

I can suggest you two solutions of the problem.
The first is to use a newer Groovy version.
The second is to surround the closure with parentheses:

new Thread({
     println "this is a test"



Please sign in to leave a comment.