30 Aug 2013

Clojure puzzler #2

Seven lines of Clojure, numbered for easy reference. From which lines do you get a reflection warning?

(set! *warn-on-reflection* true)                          ; 1
                                                          ; 2
(Thread. (fn [] (prn 1)) "foo")                           ; 3
(Thread. :x "foo")                                        ; 4
(Thread. (if true (fn [] (prn 1)) (fn [] (prn 2))) "foo") ; 5
(Thread. (if true (fn [] (prn 1)) :x) "foo")              ; 6
(Thread. (if true :y :x) "foo")                           ; 7