Clojure中的definterface和defprotocol之间的区别 [英] Difference between definterface and defprotocol in Clojure
问题描述
除了缺少文档,Clojure中的 definterface
和 defprotocol
之间有什么区别?
Other than lack of documentation, what is the difference between definterface
and defprotocol
in Clojure?
推荐答案
根据Clojure的喜悦:
According to the Joy of Clojure:
使用
definterface
超过defprotocol
的优点受限于
前者允许原始类型为
参数并返回。在将来的某个时候,同样的优势
可能会扩展到由协议生成的接口,所以使用
definterface
协议,除非绝对
必要。
The advantages of using
definterface
overdefprotocol
are restricted entirely to the fact that the former allows primitive types for arguments and returns. At some point in the future, the same advantage will likely be extended to the interfaces generated [by protocols], so usedefinterface
sparingly and prefer protocols unless absolutely necessary.
这篇关于Clojure中的definterface和defprotocol之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!