Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I specify warn-on-reflection in a clj file?

Tags:

clojure

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?

like image 669
yazz.com Avatar asked Dec 17 '10 20:12

yazz.com


2 Answers

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

like image 53
koddo Avatar answered Nov 25 '22 13:11

koddo


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.

like image 28
overthink Avatar answered Nov 25 '22 12:11

overthink