You can use map?
to check if something implements IPersistentMap
which is true for Clojure maps but not for java.utils.*
maps:
(map? (java.util.HashMap.)) ;; => false
(map? (java.util.LinkedHashMap.)) ;; => false
(map? {}) ;; => true
To be more precise you should rather check if a given object meets some requirements (e.g. is persistent, immutable/mutable - map?
will answer that specific question). There is no easy way to tell if you got a Java implementation of a map as you could get any other implementation from external library which might have a custom implementation of java.util.Map
or extending one of the concrete implementations from java.util
package.