Calling a Clojure library from a Java program. I get an IPersistentMap back.
The keys are Clojure keywords like :name etc.
But it seems I can't just do a
map.valAt(":name");
to pull it out in Java. I'm guessing that's because the keys aren't normal java Strings. So what are they? And how can I pull data out of an IPersistentMap?
You don't need to use the reader. Clojure keywords are of type clojure.lang.Keyword
. You can create one using the static method intern
:
map.valAt(clojure.lang.Keyword.intern("name")); // Note: no leading colon
Have you tried using Clojure.read
? =>
map.valAt(Clojure.read(":name"))
or maybe =>
// (:name my-map)
myMap.invoke(Clojure.read(":name"));
Clojure 1.6 Java API https://github.com/clojure/clojure/blob/master/changes.md#21-java-api
Clojure's JavaDoc https://clojure.github.io/clojure/javadoc/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With