Commits

Jesús Gómez committed 9760d53

Refection Versions

  • Participants
  • Parent commits 01b923a

Comments (0)

Files changed (3)

File Mwfaui.java

-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};
-	Method m;
-	try {
-	    m = Class.forName("Mwfaui").getMethod(fun, partypes);
-	    Double r = (Double)m.invoke(new Mwfaui(), arglist);
-	    System.out.println(r);
-	}
-	catch(Throwable e) {
-	    System.err.println(e);
-	}
-    }
-}

File MwfauiReflection.java

+import java.lang.reflect.*;
+
+class MwfauiReflection {
+    
+
+    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};
+	Method m;
+	try {
+	    m = Class.forName("MwfauiReflection").getMethod(fun, partypes);
+	    Double r = (Double)m.invoke(new MwfauiReflection(), arglist);
+	    System.out.println(r);
+	}
+	catch(Throwable e) {
+	    System.err.println(e);
+	}
+    }
+}

File mwfauireflection.py

+def f(x):
+    return x
+
+def f2(x):
+    return x*x
+
+def f12(x):
+    return x/2
+
+if __name__ == "__main__":
+    import sys
+    import mwfauireflection as m
+    fun = sys.argv[1]
+    x = float(sys.argv[2])
+
+    print(getattr(m, fun)(x))