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"
}.start()


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

';', ',' or new line expected


Thanks.

I'm using idea 9.0.3 community version.

--
Leo Jay

3 comments

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.

0

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"

}).start()

0

Please sign in to leave a comment.