我想做类似的事情:
(defrecord Base [])
(defrecord Person [])
(defrecord Animal [])
(derive Person Base)
(derive Animal Base)
(isa? Animal Person)
这可能吗?
更新:
我已经意识到这是不可能的,所以我正在做这样的事情:
(defmulti type class)
(defmethod type Base [_] ::base )
(defmethod type Animal [_] ::animal )
(defmethod type Person [_] ::person )
这有意义还是有更好的方法?
最佳答案
不,记录是 Java 类。作为multimethods页面状态:
You can also use a class as the child (but not the parent, the only way to make something the child of a class is via Java inheritance).
你不能用记录来扩展类,但你可以implement interfaces .使用接口(interface)在 Java 类层次结构中发挥作用,您也许可以使某些事情起作用。
关于clojure - 我可以使用 Clojure 的派生来创建我的 defrecord 类类型的层次结构吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4586608/