Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shargoj/099734b50f3e7991880d to your computer and use it in GitHub Desktop.
Save shargoj/099734b50f3e7991880d 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