In my language, I need objects which represent Java static methods.
My original plan was to generate code like this.
public class Function3 {
public static final int FOO = 1;
public static final int BAR = 2;
public static final int BAZ = 3;
private int which = 0;
public static final Function3 foo = new Function3(FOO);
public static final Function3 bar = new Function3(BAR);
public static final Function3 baz = new Function3(BAZ);
private Function3(which) { this.which = which; }
private static Object foo(arg1, arg2, arg3) = { ... }
private static Object bar(arg1, arg2, arg3) = { ... }
private static Object baz(arg1, arg2, arg3) = { ... }
public Object invoke(arg1, arg2, arg3) {
switch (which) {
case FOO: foo(arg1, arg2, arg3); break;
case BAR: bar(arg1, arg2, arg3); break;
case BAZ: baz(arg1, arg2, arg3); break;
default: throw new MethodInvocationError("can't happen");
}
}
}
Now I'm wondering if I shouldn't just use Method objects and
Method.invoke(). I know in the bad old days that was very slow, but
how fast is it on modern JVMs compared to the above? A
one-class-per-function solution is, I think, prohibitive.
--
GMail doesn't have rotating .sigs, but you can see mine at
http://www.ccil.org/~cowan/signatures
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---