Yes. That's what they are. Being able to add code and variables into strings is a feature of Groovy
that make Groovy
groovy. String in Groovy can be just like templates.
Now, Groovy
strings are enclosed in (") quotes. But a standard Java
String
in Groovy
is enclosed in an apostrophe ('). Standard Java
strings in groovy cannot contain variable references or code.
It makes code easier to read. Sometimes looking at all the '+' signs in Java
as part of string concatenation is a PITA.
What would you rather code and read:
println "$it.id -- ${it.firstName} --"
or
println it.id + " -- " + it.firstName + " --"
Now, with local variables it becomes much easier to read too:
Groovy
def name = "some name"
def age = 30
def waist = 42
println "Did $name really have a size $waist waist at age $age?"
Java:
String name = "some name";
int age = 30;
int waistSize = 42;
System.out.println("Did " + name + " really have a " + waist + " waist at age " age + "?";