instance?

clojure.core

  • (instance? c x)
Evaluates x and tests if it is an instance of the class
c. Returns true or false

3 Examples top

  • 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
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:135 top

(def
 ^{:arglists '([^Class c x])
   :doc "Evaluates x and tests if it is an instance of the class
    c. Returns true or false"
   :added "1.0"}
 instance? (fn instance? [^Class c x] (. c (isInstance x))))
Vars in clojure.core/instance?:
Used in 0 other vars

Comments top

No comments for instance?. Log in to add a comment.