It seems (?) like Clojure makes all integers instances of java.lang.Long. I recently found a library I use (which wraps a Java lib) was returning java.lang.Integer instead. This broke a multimethod I have which was dispatching on class.
My solution was to simply make a new defmethod to handle java.lang.Integer. It's exactly like the defmethod for handling java.lang.Long.
Is there a more elegant way to do this? Can a defmethod be made to handle a set of dispatch values? There is a common ancestor class for Integer and Long, java.lang.Number, but I don't want to use that because it will catch floats, which should fall through.
I suppose I could rewrite the dispatch to test if the class of input is Integer or Long and just dispatch those as :int and then dispatch java.lang.String as :string, although that actually may end up being more code :)
Current form is along these lines:
(defmulti int-or-nil class)
(defmethod int-or-nil java.lang.Long
(defmethod int-or-nil java.lang.Integer
(defmethod int-or-nil java.lang.String
(try (Integer/parseInt maybe-int-string)
(catch java.lang.NumberFormatException e)))
(defmethod int-or-nil :default