Last active
December 21, 2015 13:49
-
-
Save peysal/6315567 to your computer and use it in GitHub Desktop.
Introduction to groovy. Safe deferencing and auto boxing
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 | |
def spouse | |
def age | |
} | |
candidate1 = new Person(name:"bill", spouse: new Person(name:"lengloy")) | |
candidate1.spouse.spouse = candidate1 | |
assert candidate1.spouse.spouse != null | |
candidate2 = new Person(name:"bull") | |
assert candidate2.spouse?.name == null //defendsive programming groovy style. Safe dereferencing | |
candidate1.age = 32 | |
assert candidate1.age.class == Integer.class | |
candidate2.age = 30.5 | |
assert candidate2.age.class == BigDecimal.class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment