Type hinting for functions in Clojure

Posted by mikera on Stack Overflow See other posts from Stack Overflow or by mikera
Published on 2010-06-10T21:20:58Z Indexed on 2010/06/10 21:42 UTC
Read the original article Hit count: 181

I'm trying to resolve a reflection warning in Clojure that seems to result from the lack of type inference on function return values that are normal Java objects.

Trivial example code that demonstrates the issue:

(set! *warn-on-reflection* true)    

(defn foo [#^Integer x] (+ 3 x))

(.equals (foo 2) (foo 2))

=> Reflection warning, NO_SOURCE_PATH:10 - call to equals can't be resolved.
   true

What is the best way to solve this? Can this be done with type hints?

© Stack Overflow or respective owner

Related posts about java

Related posts about reflection