[armedbear-devel] Using Java variable arguments
Erik Huelsmann
ehuels at gmail.com
Fri Jan 29 20:46:24 UTC 2010
Hi Blake,
On Sun, Jan 24, 2010 at 3:31 AM, Blake McBride <blake at mcbride.name> wrote:
>
> Java has had support for variable argument methods since version 5.
> Wouldn't it be cleaner to use that? For example, in LispObject.java there
> are several "execute" methods, one to support various numbers of arguments.
> In Java 5+ you could write:
> public LispObject execute(LispObject ... arg) { whatever }
> You call it like you do now, i.e. execute(a, b, c, d)
> but arg gets an array of the arguments.
> This way you could create one method that would handle virtually any number
> of arguments in one clean method.
> I'm sure this technique can be used in more places too.
Yes. It can, however, the technique you're seeing is used to handle
"wrong number of arguments" automatically: a function overrides only
the execute methods with the number of arguments it knows how to
handle. The other ones point to the original definition. Those are
pre-programmed to generate "Wrong number of argument" exceptions.
We have a branch started which reduces the number of execute methods
by creating a single array argument method. However, the impact of
that is huge. We wanted to spend that time on improving other stuff
such as the stuff we've been addressing over the past year. I've put
the branch back on ice for now. The idea still lives, but we can gain
much more from handling other issues at this moment.
I hope that explains and provides the right context!
Bye,
Erik.
More information about the armedbear-devel
mailing list