如何对数组类型分配多方法 [英] How to dispatch a multimethod on the type of an array
本文介绍了如何对数组类型分配多方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个多方法,需要更新一个哈希序列中的一堆不同的东西。看起来相当直截了当,直到我试图输入'X的数组类型。
I'm working on a multimethod that needs to update a hash for a bunch of different things in a sequence. Looked fairly straitforward until I tried to enter the 'type of an array of X'.
(defmulti update-hash #(class %2))
(type (byte 1))
=> java.lang.Byte
(defmethod update-hash java.lang.Byte [md byte]
(. md update byte))
(type (into-array [ (byte 1)]))
=> [Ljava.lang.Byte;
(defmethod update-hash < WHAT GOES HERE > [md byte]
推荐答案
这两个都应该工作:
(defmethod update-hash (Class/forName "[Ljava.lang.Byte;") [md byte] ...)
(defmethod update-hash (class (make-array Byte 0)) [md byte] ... )
这篇关于如何对数组类型分配多方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文