Created
May 28, 2011 16:06
-
-
Save fumokmm/996983 to your computer and use it in GitHub Desktop.
Groovy's operator override Test.
This file contains hidden or 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 NumHolder { | |
int num = 0 | |
def plus(int n) { num += n; println 'puls!'; this } | |
def minus(int n) { num -= n; println 'minus!'; this } | |
def negative() { num = -num; println 'negative!'; this } | |
} | |
def nh = new NumHolder() | |
assert 0 == nh.num | |
nh += 1 | |
assert 1 == nh.num | |
nh = -nh | |
assert -1 == nh.num | |
nh -= 1 | |
assert -2 == nh.num |
Author
fumokmm
commented
May 28, 2011
puls!
negative!
minus!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment