gpt4 book ai didi

clojure - "No single method [...] found for function"尝试使用协议(protocol)

转载 作者:行者123 更新时间:2023-12-03 00:26:37 25 4
gpt4 key购买 nike

我有一个 Clojure 库,它定义了 MQHandle 协议(protocol)并扩展了它

(ns example.mq
(:import [java.util.concurrent BlockingQueue]))

(defprotocol MQHandle
(send-message [this key body & params])

(extend-type BlockingQueue
MQHandle
(send-message [this key body & params]
(.put this (merge {::key key, ::body body}
(into {} (partition 2 params)))))

(defn get-handle ^BlockingQueue [& config]
"return a BlockingQueue tied to a thread which consumes messages
and submits them to a remote message queue"
...)

...但是当我尝试使用它时:

(require '[example.mq :as mq])

(def handle (mq/get-handle config))

(satisfies? mq/MQHandle handle)
; => true

(mq/send-message handle "key" "body")
; java.lang.IllegalArgumentException: No single method: send_message of interface:
; com.indeed.clojure_network_repl.mq.MQHandle found for function: send-message of
; protocol: MQHandle

我不明白这个异常的含义,或者我应该采取什么不同的做法。

最佳答案

协议(protocol)函数不支持剩余参数。

关于clojure - "No single method [...] found for function"尝试使用协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10435480/

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