How to dispatch a multimethod on the type of an array

我的未来我决定 提交于 2019-12-23 07:55:48

问题


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]

回答1:


Either of these should work:

(defmethod update-hash (Class/forName "[Ljava.lang.Byte;") [md byte] ...)

(defmethod update-hash (class (make-array Byte 0)) [md byte] ... )


来源:https://stackoverflow.com/questions/2782901/how-to-dispatch-a-multimethod-on-the-type-of-an-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!