反射不会在 JVM 调用之间返回相同的方法顺序(通过 Class::getMethods)。当将可调用和可运行(Callable 和 Runnable)的 Clojure 函数提交给执行器时,这可能是最明显的。
(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