我写了一个相当原始的测试程序(我正在编写一个围绕LWJGL的OpenGL类的包装器,主要是出于美学原因,我决定在那里引入多线程,因为我之前从未编写过并发程序).程序结束后,我总是收到警告
我实际上在程序进入main函数之前得到了警告.抱歉混淆(我想这可能不是我的程序,而是clojure本身的东西):
Reflection warning, NO_SOURCE_PATH:1 - call to invokeStaticMethod can't be resolved.
Run Code Online (Sandbox Code Playgroud)
我在编译期间没有收到任何警告,我觉得很奇怪.无论如何,这是程序:
(ns opengltuts.core
(:import (org.lwjgl.opengl GL11 Display))
(:use opengltuts.opengl)) ;my wrapper
(def world-state (ref {:running true :color [1.0 0.0 0.0 1.0]}))
(defn render-world [state]
(apply glClearColor (:color state))
(glClear GL11/GL_COLOR_BUFFER_BIT)
(Display/update))
(defn render []
(Display/create)
(loop []
(let [world @world-state]
(when (:running world)
(do (render-world world)
(recur)))))
(Display/destroy))
(defn -main []
; without the annotation, I get a warning here too.
(let [render-thread (doto (Thread. ^Runnable render) (.start))]
(Thread/sleep 3000)
(dosync (commute world-state assoc :color [0.0 1.0 0.0 1.0]))
(Thread/sleep 3000)
(dosync (commute world-state assoc :running false))
(.join render-thread)))
Run Code Online (Sandbox Code Playgroud)
这可能不是太习惯了(我听说在Clojure中你通常不会启动线程new Thread,而是使用Agent或其他东西,但我还没有完全掌握它是如何工作的),但我想这么短的程序没关系.
您的 Clojure 源代码在运行时加载和编译(请参阅http://clojure.org/compilation),这就是为什么在程序执行之前您看不到反射警告。
很难确定在何处对静态方法进行反射调用,因此我建议执行以下步骤:
(:gen-class)到您的(ns)声明中(set! *warn-on-reflection* true)或。(binding [*warn-on-reflection* true] body)