【问题标题】:Why IllegalArgumentException "interface is not a protocol" when importing a Clojure protocol?为什么导入 Clojure 协议时出现 IllegalArgumentException “接口不是协议”?
【发布时间】:2021-02-05 08:09:10
【问题描述】:

当在与 defprotocol 不同的命名空间中使用 extend-protocol 时,我按照 Cursive 的建议导入类

(ns the.first)
(defprotocol AProtocol
  (method [this]))

(ns the.second
  (:import (the.first AProtocol)) ; <= Cursive suggested this...
(extend-protocol AProtocol ; <= ...because this wasn't in scope.
  AType
  (method [this] ...))

我在IllegalArgumentException: interface the.first.AProtocol is not a protocol 上扯了一点头发。

【问题讨论】:

    标签: clojure namespaces protocols


    【解决方案1】:

    然后我意识到我应该忽略 IDE 的提示,并 :required 协议(和方法,为方便起见)。

    (ns the.second
      (:require [the.first :refer [AProtocol amethod]]))
    

    只有回想起来才明显。

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 1970-01-01
      • 2015-02-03
      • 2011-03-19
      • 2017-08-06
      • 2016-05-30
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多