I've been browsing the documentation and came across the part about how
variable arguments are handled (Appendix B in the parser doc). The method
currently used seems to be to make a bunch of methods with 0..N extra
arguments at the end.
For extremely time-critical code, this is definitely the way to go.
However, most of the time, I'd recommend just taking an array of the
appropriate type. Actually, there's a proposed change to the Java language
(well, it's a JSR in-progess, at least, and seems likely to be approved)
which would make it syntactically easy to write an array of type Object,
so, I'd even be willing to forego the compile-time typecheck to get the
better syntax. (After all, it's easy enough to generate the cast.) See this
URL for details on the proposal:
<http://java.sun.com/aboutJava/communityprocess/jsr/jsr_065_cncsarray.html>
The brief synopsis is that the following two forms would become equivalent:
foo.bar (a, b, new Object[] { c, d, e })
foo.bar (a, b, { c, d, e })
If you still have some efficiency concerns, my usual recommendation is
to provide a limited number of separate-arg versions (e.g., for 0 to 2
args) and then provide the array version as a catch-all, e.g.:
public void meth (String s);
public void meth (String s, Foo foo1);
public void meth (String s, Foo foo1, Foo foo2);
public void meth (String s, Foo[] foos); // or Object[] foos
Hope you find this useful,
-dan
|