以下是一个有效的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))
然而,当检查this
被提供的:标签元数据时,它看起来有一个相当奇怪的形式(因为它仍然是调用链,而不是类字面量)
(-> (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))}
所以,:标签看起来像是一个函数调用。编译器会不会最终调用(class (log-window-proxy ...
以获取它实际上可用的类型提示类?
否则,我会担心这个:标签元数据是无效的,这可能会导致反射警告,并可能混淆第三方工具。