Other Groovy Syntax Step 9
There are other important syntax changes in groovy that you need to know.
semicolins are optional
Braces are optional for example
println("hello world!")
can be written
println "Hello world!"
You still need parentheses if a method has no arguments.
def s="Hello"
println s.toUpperCase()
There are some ways around using braces such as using method pointers.
def pizza=new Pizza()
def deliver=pizza.&deliver()
deliver
A return statements is also optional.
You can write a method like this:
String getFullName(){
return "${firstName} ${lastName}"
}
String getFullName(){
"${firstName} ${lastName}"
}
In the last method, the return statement is implied.
Go To Step 10

0 comments:
Post a Comment