gpt4 book ai didi

clojure - 调用 invokeStaticMethod 无法解决?

转载 作者:行者123 更新时间:2023-12-03 17:54:55 24 4
gpt4 key购买 nike

我写了一个相当原始的测试程序(我主要是出于审美原因编写了一个关于 LWJGL 的 OpenGL 类的包装器,我决定在那里引入多线程,因为我之前实际上从未编写过并发程序)。程序完成后,我总是收到警告

我实际上在程序进入主函数之前收到了警告。抱歉造成混淆(我认为这可能根本不是我的程序,而是 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 开始线程,而是用 Agents 或其他东西,但我还没有完全掌握它是如何工作的),但我想对于这样的一个无关紧要的简短节目。

最佳答案

您的 Clojure 源代码正在运行时加载和编译(请参阅 http://clojure.org/compilation ),这就是您在程序执行之前看不到反射警告的原因。

很难确定对静态方法进行反射调用的位置,因此我推荐以下步骤:

  • 添加 (:gen-class)给您的 (ns)声明
  • 添加 (set! *warn-on-reflection* true)(binding [*warn-on-reflection* true] body)您怀疑正在发生反射调用的地方。
  • 关于clojure - 调用 invokeStaticMethod 无法解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12881538/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com