Auto boxing - not enough coffee and ... Infix call corresponds to a dot-qualified call 'it.id.compareTo(5L)' which is not allowed on a nullable receiver 'it.id'. Use ?. qualified instead


#1

Ok, so there isn't enough coffee running through my system, I've got a compiler error on the '>' below:

it.id > 5L

The compiler error seems pretty clear “Infix call corresponds to a dot-qualified call ‘it.id.compareTo(5L)’ which is not allowed on a nullable receiver ‘it.id’.  Use ?. qualified instead”

… but I spin for 5 minutes qualifying the “id” with attempts like  it!!.id

Ah, Rob you muppet, the id is an nullable object Long … and Kotlin is saying it won’t auto unbox that down to a primitive long so the solution is actually:

it.id!!.toLong() > 5L

Now, it could be that I’m just a bit slow today and low on coffee in the bloodstream but it could also be that Java’s auto boxing has weakened my brain and it did take some time for me to actually interpret the problem correctly.  That makes me wonder if this type of compiler error for the cases of auto boxing could actually be tweaked / improved - perhaps something like … “Rob you muppet, you are comparing a nullable Object Long to a primative long and that is silly - qualify it with a !! or ?.   … and go get a coffee!!”