Using type hints to return values in clojure

I'm developing some Java / clojure interoperability and found reflection warnings 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 because getresource always returns a URL, so I want the compiler in javax imageio. Use appropriate static methods in imageio / read

The code works well with btw, so it clearly finds the correct method at run time

So there are two questions:

>Why does this return a reflection warning? > What type of tips do I need to solve this problem?

Solution

Afaics has nothing to do with your code or compilation It is part of the repl's source FN function:

...
      (let [text (StringBuilder.)
            pbr (proxy [PushbackReader] [rdr]
                  (read [] (let [i (proxy-super read)]
                             (.append text (char i))
                             i)))]
 ...

And used to display the source code in repl shell (afaict)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>