Skip to content

Instantly share code, notes, and snippets.

@brandonbloom
Created May 2, 2014 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brandonbloom/1636c60c176f992cb60c to your computer and use it in GitHub Desktop.
Save brandonbloom/1636c60c176f992cb60c to your computer and use it in GitHub Desktop.
(import '[clojure.lang Reflector])
(defn static-invoke [class member & args]
(if (zero? (count args))
(try
(Reflector/getStaticField class member)
(catch Exception e
(Reflector/invokeStaticMethod
class member clojure.lang.RT/EMPTY_ARRAY)))
(Reflector/invokeStaticMethod class member (object-array args))))
(defn staticfn [class member]
(fn [& args]
(apply static-invoke class member args)))
(deftype Point [x y])
((staticfn (class (Point. 5 10)) "getBasis"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment