Right, you need to import or qualify the packages:
(defn load-image [name]
  #^BufferedImage (. javax.imageio.ImageIO (read (new java.io.File
name))))

However, since it didn't give me an error for BufferedImage, I think
the compiler is just ignoring it in either of your examples.  Clojure
doesn't declare a function return type like java, it's always
effectively java.lang.Object.

Type hints are an optimization (not required) so the compiler can
avoid reflection and they are used in the calling code, not in the
function declaration, sort of like a cast in java.

(defn load-image [name]
 (. javax.imageio.ImageIO (read (new java.io.File #^String name))))

(.createGraphics #^java.awt.image.BufferedImage (load-image "..."))

And this will fail without qualifying BufferedImage.

(set! *warn-on-reflection* true) will tell you when the compiler wants
a hint.  (I found this doesn't work in Slime, because it doesn't do
anything with System.err.)

-Mike

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to