Well first I'd say that the Java api you're calling into isn't very good if
it expects specifically java.util.HashMap. Clojure's map data structures
implement java.util.Map so generally they can be passed into Java api
methods that take the interface (good practice).
However, HashMap has a constructor that takes a map, so just calling:
(java.util.HashMap. {:a 1 :b {:c 1 :d 2} :e {:f 10 :g 11}})
should work. If you want to do it recursively, you can use
clojure.walk/postwalk, something like:
(postwalk #(if (map? %) (java.util.HashMap. %) %) my-data)
On Sunday, September 14, 2014 7:16:04 PM UTC-5, webber wrote:
>
> I am writing clojure code calls java's method which parameters and return
> are HashMap.
>
> When I call java method with clojure's Map, the following error occurred.
>
> java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot
> be cast to java.util.HashMap
>
>
> So, I'd like to convert nested clojure.lang.PersistentArrayMap into
> java.util.HashMap
> and nested HashMap into PersistentArrayMap.
>
> Clojure's map is like {:a 1 :b {:c 1 :d 2} :e {:f 10 :g 11}}.
>
> Is there the efficient way to convert type between Clojure's map and
> java's map ?
>
> Thanks,
> Makoto
>
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.