我已經寫了一個相當原始的測試程序(我主要是爲了審美原因編寫一個LWJGL的OpenGL類的包裝器,並且我決定在其中引入多線程,因爲我之前從未寫過併發程序)。 當程序結束時,我總是得到警告調用invokeStaticMethod無法解析?
我實際上在程序進入主函數之前得到警告。很抱歉的混亂(我認爲這可能不是我的程序可言,而是一些Clojure中本身):
Reflection warning, NO_SOURCE_PATH:1 - call to invokeStaticMethod can't be resolved.
我不明白編譯過程中的任何警告,雖然,我覺得這很奇怪。不管怎麼說,這是程序:
(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)))
這可能是不太習慣(我聽說在您的Clojure一般不與new Thread
啓動線程,而是與代理商或東西,但我不完全掌握它如何工作),但我想這樣一個簡短的程序並不重要。
如果你需要一個簡單的線程,你可以使用'future',而不是代理。即'(未來(渲染))'。此外,'線程/睡眠'是好的,請參閱http://clojuredocs.org/clojure_core/clojure.core/future – noahlz
你確定警告不是來自'opengltuts.opengl'嗎?某處,您正在調用重載的靜態方法,並且無法解析確切的調用。關於它在運行時發生,您是否在運行時生成代碼? – noahlz
@noahz不,我沒有生成代碼。這隻發生在程序結束時,我已經完成調用opengl函數。 此外,使用未來這是有點奇怪。它確實爲我節省了一些點數,但現在我最終需要這個奇怪的調用(shutdown-agents),因爲clojure無法知道什麼時候該退出了。哦,當然,取消引用一個零值,導致一個副作用也不坐在我身邊。 我誤解了時機 - 我在進入主要功能之前收到警告。 – Cubic