Created
October 19, 2010 22:46
-
-
Save tbatchelli/635307 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; reflection | |
(defn method-call-fn [method-name return-type parameter-types] | |
(let [o-symbol (symbol "o") | |
method-symbol (symbol (eval method-name)) | |
args (map #(with-meta (symbol (str "x" %2)) {:tag %1}) parameter-types (range))] | |
(eval `(fn [~o-symbol ~@args] (. ~o-symbol ~method-symbol ~@args ))))) | |
(defn get-signature [^java.lang.reflect.Method method] | |
(let [method-name (.getName method) | |
return-type (.getReturnType method) | |
parameter-types (vec (.getParameterTypes method))] | |
{:method-name method-name | |
:return-type return-type | |
:parameter-types parameter-types})) | |
(comment | |
(def eval-method-call (method-call-fn "equals" boolean [java.lang.Object])) | |
(eval-method-call "hello" "hello") | |
;; true | |
(eval-method-call "hello" "goodbye") | |
;; false | |
) |
hugoduncan
commented
Oct 20, 2010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment