On Feb 21, 8:31 am, Richard Lyman <richard.ly...@gmail.com> wrote:
> I have an instance of the Java class in a variable.
> I have the method arguments in a vector.
> I have the method name as a String.
>
> I've tried so many different ways to invoke that method on that class and
> pass those parameters. I've tried macros, reflection, and read/eval. None of
> the ways I've tried feel right, and none of them have worked so far. Rather
> than dump all the failed code, here's some pseudo-code that I wish worked...
>
> (prn "Result: "
>        (apply (memfn-from-string "nameOfMethod")
>                  class-instance
>                  [arg1 arg2 arg3]))
>
> Any pointers? What am I not seeing? Am I wanting too much?

You can old plain old Java-reflection:

;; get a reference to the method you need
(def method (.getMethod (Class/forName "java.lang.String")
"toUpperCase" nil))

;; reflectively call the method
(.invoke method "foo" nil)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to