Comparing zeros and numbers in groovy

Why in groovy?

0 > null 

Is this optional or is it just a consequence of the implementation of compareTo?

I am using Groovy 2.0.5.

+7
source share
1 answer

In Groovy, null is the smallest possible element, so everyone > null

 assert 'tim' > null assert 0 > null assert -1 > null assert Double.NEGATIVE_INFINITY > null 

This means that such things can work:

 [ 1, null, 3 ].sort() 

Otherwise, what will happen? If you want this to work, you must say: "null is less than anything" or "null is more than anything" ...

Groovy chose the former

+10
source

All Articles