(instance? c x)
Evaluates x and tests if it is an instance of the class c. Returns true or false
user=> (instance? Long 1)
true
user=> (instance? Integer 1)
false
user=> (instance? Number 1)
true
user=> (instance? String 1)
false
user=> (instance? String "1")
true
user=> (def al (new java.util.ArrayList))
#'user/al
user=> (instance? java.util.Collection al)
true
user=> (instance? java.util.RandomAccess al)
true
user=> (instance? java.lang.String al)
false
;; Some things are more than what they seem to be at first glance
user=> (instance? clojure.lang.IFn +)
true
user=> (instance? clojure.lang.Keyword :a)
true
user=> (instance? clojure.lang.IFn :a)
true
user=> (instance? clojure.lang.IFn {:a 1})
true
;; If `c` is specified with a literal class name, this is a Java
;; class name. If any of the namespace components of the class
;; include dashes, the dashes have to be replaced with underscores:
(ns foo-bar)
(defrecord Box [x])
(def box (Box. 42))
(instance? foo-bar.Box box)
;=> CompilerException java.lang.ClassNotFoundException: foo-bar.Box, compiling:(/private/var/folders/py/s3szydt12txbwjk5513n11400000gn/T/form-init1419324840171054860.clj:1:1)
(instance? foo_bar.Box box)
;=> true
;; This rule doesn't apply to the last component of the class name:
(defrecord My-Box [x]) ; not an idiomatic choice
(def mybox (My-Box. 42))
(instance? foo_bar.My-Box mybox)
;=> true