慢速调用clojure代理

Zub*_*air 3 clojure

我在clojure中有一个应用程序,大量使用名为Vaadin的Java框架.Vaadin使用clojure的Java"代理"功能使用了几个回调.但是,每次在clojure函数中调用代理时,都会有很长的延迟(有时是100毫秒).有什么方法可以加快速度吗?

Ral*_*lph 6

我的理解是新reify宏比速度快proxy.如果您只需要实现单个接口,则可以使用它.

例如,如果您需要实现a java.awt.event.ActionListener,则可以使用如下代码:

(import 'java.awt.event.ActionListener 'javax.swing.JButton)
(let [a-button (JButton. "Click Me")]
  (.addActionListener a-button
    (reify ActionListener
      (actionPerformed [this ev] (comment do something interesting)))))
Run Code Online (Sandbox Code Playgroud)

  • 实际上,可以在单个"reify"形式中实现多个接口.对``proxy`的限制是`reify`不能扩展类. (5认同)