Commits

Jeús Gómez committed 78de9f0

Prelimiray Java version without taking advantage of Reflection

Comments (0)

Files changed (1)

+import java.util.HashMap;
+import java.util.Map;
+import java.lang.reflect.*;
+
+class Mwfaui {
+    
+
+    public double f(double x)
+    {
+	return x;
+    }
+
+    public double f2(double x)
+    {
+	return x*x;
+    }
+
+    public double f12(double x)
+    {
+	return x/2;
+    }
+
+    public static void main(String args[])
+    {
+	String fun = args[0];
+	Double x = Double.parseDouble(args[1]);
+	Object arglist[] = {x};
+	Class partypes[] = {Double.TYPE};
+	Map<String, Method> mapfun = new HashMap<String, Method>();
+	try {
+	    mapfun.put("f", Class.forName("MwfauiReflection").getMethod("f", partypes));
+	    mapfun.put("f2", Class.forName("MwfauiReflection").getMethod("f2", partypes));
+	    mapfun.put("f12", Class.forName("MwfauiReflection").getMethod("f12", partypes));
+
+	    Double r = (Double)mapfun.get(fun).invoke(new MwfauiReflection(), arglist);
+	    System.out.println(r);
+	}
+	catch(Throwable e) {
+	    System.err.println(e);
+	}
+    }
+}