反射不会在不同的 JVM 调用中返回相同的方法顺序(通过 Class::getMethods)。这在将 Clojure 函数(Callable 和 Runnable)提交到执行器时最为明显。
(ns repro)
;;(set! *warn-on-reflection* true)
(defn repro
[]
(let [exec (java.util.concurrent.ForkJoinPool/commonPool)
work #(do 1)]
(deref (.submit ^Object exec work)))) ;; 故意使用反射
(defn -main []
;; dereffing a runnable returns nil, a callable can return a value, in this case an integer
(System/exit (or (repro) 0)))
nondeterministic ➜ while true; do clojure -m repro; echo $?; done
0
0
0
1
0
0
0
1
0
0
0