Using type hints in Clojure for Java return values

Posted by mikera on Stack Overflow See other posts from Stack Overflow or by mikera
Published on 2010-06-01T22:53:14Z Indexed on 2010/06/02 6:53 UTC
Read the original article Hit count: 242

Filed under:
|
|

I'm working on some Java / Clojure interoperability and came across a reflection warning for the following code:

(defn load-image [resource-name]
  (javax.imageio.ImageIO/read 
    (.getResource 
      (class javax.imageio.ImageIO) 
      resource-name)))

=> Reflection warning, clojure/repl.clj:37 - reference to field read can't be resolved.

I'm surprised at this because getResource always returns a URL and I would therefore expect the compiler to use the appropriate static method in javax.imageio.ImageIO/read.

The code works fine BTW so it is clearly finding the right method at run time.

So two questions:

  1. Why is this returning a reflection warning?
  2. What type hint do I need to fix this?

© Stack Overflow or respective owner

Related posts about java

Related posts about clojure