javafx - Clojure: Calling .invoke without knowing arg types at compile time -


i'm trying figure out way .invoke() methods of single arg, without knowing type of arg @ runtime.

for example, passing property name following function, i'd set property's value. it's hard-coded double/type, function should allowed take type of value arg.

the property names, , therefore type of arg value not known until runtime, appears method requires array of primitives, @ least number types.

(defn set-prop-val!   "sets property value value.  uses reflection."   [obj prop value]   (let [methodname (str "set" prop)]     (.. obj         getclass         (getmethod methodname (into-array [double/type]))         (invoke obj (into-array [value]) ))))  (set-prop-val! (button.) "translatex" 13.99) 

in above function, trying instead (getmethod methodname (into-array [(class value)])) doesn't work, , nosuchmethodexception javafx.scene.control.button.settranslatex(java.lang.double) because wants double not double.

what i'd numbers primitive type @ runtime, attempts @ calling static method instance have failed, eg (. (class 19.5) type) (in case illegalargumentexception no matching field found: type class java.lang.class)

it seems double/type works, though (= (class 19.5) double) returns true.

so few questions come out of this:

  1. how call static method, such type instance?
  2. is there use double-array here? me array carry values .invoke, doesn't appear necessary anyway, not class[double] array needed .getmethod.
  3. should use clojure.reflect instead?

i found use clojure.lang.reflector/invokeinstancemethod need.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -