tags:

views:

24

answers:

1

When i try execute the following code, which should just print a slashy string in groovy console version 1.7.4 i get a compilation error:

println /slashy string/

if i change this to:

def s = /slashy string/; println s

everything is fine and the expected string is printed.

Any ideas what i am doing wrong?

+1  A: 

The final gotcha (on the linked doc) says, a slashy string cannot be used with assert, because of a grammar limitation. Since println is also a part of the grammar (afaik, since its not a classical java function), I would guess this applies here, too.

It says to use braces around it:

println (/slashy string/)

This worked fine in my groovy shell.

ZeissS
@ZeissS: Yeah, this is working in my groovy shell too ;-) Thanks for your answer. I read the hint about the grammar limitation but i thought that only applies for assert statements (maybe the doc is not exact at this part).from the groovy doc:currently a slashy string can't be the left hand side (LHS) expression of an assert statement
hochraldo