以下是一个有效的Clojure代码(注意extend-type (class (log-window-proxy nil))
,而不是引用类字面量)
(defn- log-window-proxy [state]
(proxy [javax.swing.JTextArea clojure.lang.IDeref] []
(deref [] state)
(scrollRectToVisible [rect]
(if @(:auto-scroll? state)
(proxy-super scrollRectToVisible rect)))))
(defprotocol LogWindow
(log [this message])
(clear [this]))
(extend-type (class (log-window-proxy nil))
LogWindow
(log [this message]
(println "message" message))
(clear [this]
nil))
:tag元数据的形式似乎有些奇怪(因为它仍然是一系列调用的链接,而不是类字面量)
(-> (extend-type (class (log-window-proxy nil))
LogWindow
(log [this message]
(println "message" message))
(clear [this]
nil)) quote macroexpand last :log second ffirst meta)
;; => {:tag (class (log-window-proxy nil))}
所以,:tag看起来像是一个函数调用。编译器最终会调用(class (log-window-proxy ...
来获取一个可以用作类型提示的类吗?
否则,我会担心此:tag元数据无效,这可能导致反射警告,并且还可能混淆第三方工具。