I am trying to use warn-on-reflection in a clj file. When I write:
(set! warn-on-reflection true)
: after the ns declaration I get the error:
java.lang.Exception: Unable to resolve symbol: warn-on-reflection in this context
Does anyone know why?
Global variables are conventionally named with names that start and end with asterisk.
(set! *warn-on-reflection* true)
I guess you copied that from a forum which makes such text bold.
Update: add these lines in your leiningen project.clj:
;; Emit warnings on all reflection calls.
:global-vars {*warn-on-reflection* true}
https://github.com/technomancy/leiningen/blob/master/sample.project.clj
The (set! *warn-on-reflection* true)
is probably the way to go. If you do want to use lein-specific methods to do this, here is some updated info for 2.x:
To set the global in the project definition:
(defproject foo ...
:global-vars {*warn-on-reflection* true}
...)
Or just periodically run lein check
, as it will warn on reflection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With