Between null and positive infinity
A funny null fact I found out after so many years of working with groovy.
Problem
I happen to create a construction like this:
1
2
3
4
5
if(object?.value > 0) {
println "did something"
} else {
println "did nothing"
}
Are you sure what will be printed when object is null?
I must say I wasn’t.
We got used to negate null in groovy like this:
but what about using null with relation operator?
Turns out
All this below will execute:
1
2
3
assert null < 0
assert null < Integer.MIN_VALUE
assert null < Double.NEGATIVE_INFINITY
so lets remember.. null is the lower then anything.
Written on August 19, 2016