Created
August 23, 2013 04:13
-
-
Save peysal/6315473 to your computer and use it in GitHub Desktop.
Introduction to groovy 1) duck typing
2) return is optional, last statement will be taken
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
def name //duck typing | |
def age | |
def getName() { //override default getter | |
"will not be printed" | |
"my name is ${name}" //return is optional, last statement is taken | |
} | |
} | |
person = new Person(name:"goku") | |
println "hello " + person.name | |
assert "hello " + person.name == "hello my name is goku" | |
assert "hello " + person.name == "hello ${person.name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment