Sunday, April 17, 2016

The spaceship operator

Just ran into this and I thought it was really cool.

So the spaceship operator (<=>) delegates to the compareTo method:

assert (1 <=> 1) == 0
assert (1 <=> 2) == -1
assert (2 <=> 1) == 1
assert ('a' <=> 'z') == -1

For more checkout http://groovy-lang.org/operators.html

No comments:

Post a Comment