Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to tokenize the String. (if it always starts with <code>f(</code> and ends with <code>)</code> you can make your life easier, be removing these parts).</p> <p>A(4) -> Find the Classname -> A -> find the Parameter -> 4</p> <p>This is done like this (pseudo java code):</p> <pre><code>public static Object createClass(String className, Double value){ Class a = Class.forName(className); Class[] params = new Class[]{Integer.class}; Constructor c = a.getConstructor(params); Object[] values = new Object[]{value}; return c.newInstance(); } </code></pre> <p>Maybe, this lik is helpful: <a href="http://docs.oracle.com/javase/tutorial/reflect/member/ctorInstance.html" rel="nofollow">http://docs.oracle.com/javase/tutorial/reflect/member/ctorInstance.html</a></p> <p><strong>update</strong> This is like writing a compiler. You can get further information, if you read something about, how to write a compiler: <a href="http://en.wikipedia.org/wiki/Compiler" rel="nofollow">http://en.wikipedia.org/wiki/Compiler</a></p> <p><strong>update 2</strong> put all generated instances into an array. Now you can get the correct method f with the reflections-API. The Code will be something like </p> <p><a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getDeclaredMethod(java.lang.String" rel="nofollow">http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getDeclaredMethod(java.lang.String</a>, java.lang.Class...)</p> <pre><code>Object[] values ... Class[] classes ... for(Object o: values){ add o.getClass() to classes } Method f = Functions.getClass().getDeclaredMethods("f", classes); f.invoke(values); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload