Why is the following true in Groovy?
0 > null
Is it by choice or is it just a consequence of the implementation of compareTo?
I'm using Groovy 2.0.5.
In Groovy null
is the lowest possible element, so everything is > null
assert 'tim' > null
assert 0 > null
assert -1 > null
assert Double.NEGATIVE_INFINITY > null
This means things like this can work:
[ 1, null, 3 ].sort()
Otherwise what would happen? If you want this to work, you have to say "null is lower than anything" or "null is higher than anything"...
Groovy chose the former
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With