Wednesday, November 11, 2009

Groovy - Sometimes you still need a semicolon

I Was ploughing through my overly-large blogroll the other night when this article caught my eye.
http://groovy.dzone.com/articles/groovy-sometimes-you-still
I gave it a read, because I wanted to know all the cases where you had to have a semicolon.

He gives two examples, the first of which he’s wrong about, it works fine in 1.6.5 and I believe it works for anything >= 1.6.
def list = [1,2,3] as List<Integer>
println list

This second one (not the exact same example he used) does need a semicolon
{-> assert true == true }()
{-> assert false == false }()

Should be
{-> assert true == true }();
{-> assert false == false }()

This is only the case if you have two closure calls next to each other with nothing in between.
{-> assert true == true }()
println ""
{-> assert false == false }()
works fine.

Are there other times when you need a semicolon at the end of the line (assuming only one statement per line)?