1
votes

I'm new on coding. My first lang is Clojure. And it's my first question on stackoverflow.

I wrote a Clj code, tested all functions on lein(Emacs/Cider) and I want to compile for testing. But Java methods returned this error message :

(on terminal in project folder):

aaron@debian:~/img-process$ lein check

Reflection warning, img_process/core.clj:25:30 - reference to field getWidth can't be resolved.

(and getHeight, getRGB, setRGB, java.io.File, javax.imeageio.ImageIO, java.lang.String)

Why lein can not see Java elements ? How can I compile this ?

Thank you.

project.clj https://github.com/harununal/clj-x-ray-coloring/blob/master/project.clj

core clj : https://github.com/harununal/clj-x-ray-coloring/tree/master/src/img_process

1

1 Answers

1
votes

If Clojure cannot imply the type of a Java object, it falls back on reflection for interop which is much slower. If you use:

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

Then you'll see these warnings at the REPL too. If you type hint your methods, then Clojure can see the types and emit much better code. e.g.

(defn get-img-coords
  [^BufferedImage img]
  (for [y (range (.getHeight img))
        x (range (.getWidth img))]
    [x y]))

Note that lein check isn't a compiler - it's the lein equivalent of a light linter, perhaps, checking for these warnings and others.