Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure by

(< nil 3) produces the error Cannot invoke "Object.getClass()" because "x" is null. Is there any room for improvement here?

My gut tells me that this hasn't been done due to performance reasons, but another user made the observation in Slack that it's in the static public Boolean lt(Object x, Object y) { branch of Numbers.java, so it might not be terrible to add the null checks to improve the error message.


1 Answer

+1 vote

Your gut is correct about the perf consideration. I'd love to see a timing comparison between the existing code and one that checks nulls. Any potential change (or not) would start with that I think.

Is this something that could be handled by overloads for `null` inputs? `Boolean lt(null x, Object y) {} Boolean lt(Object x, null y) {} Boolean lt (null x, null y) {}` or similar?