varargs in BeanShell

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

varargs in BeanShell

Kireitchik, Valeri
varargs in BeanShell

I would like to return to the question about support of varargs in beanshell scripts.

We are using java library that has a lot of methods with varargs. It is very convinient to use them in javacode but looks ugly in scripts as it is necessary to wrap method parameters in arrays.

Instead of

    x.m(a, b, c);

you should write

    x.m(new MyClass[]{a, b, c});

I believe that 1st way is more scripty than 2nd is.

Until now we assumed this inconvinience as temporary one, and now we need just to know the time when we can expect possibility of calling varargs methods from script whithout wrapping parameters in array.

Best regards

Valeri Kireitchik

Reply | Threaded
Open this post in threaded view

Re: varargs in BeanShell

Andreas Rozek
Hello Valeri!

I do not exactly know  if this would help you,  but I've written
a "mechanism" which allows for BeanShell commands  with variable
argument lists - just yesterday.

The mechanism relies on BeanShell's "invoke" method which I have
implemented to scan a dictionary  for the requested command.  If
the command is found in that dictionary,  it is invoked with the
Object[] passed to "invoke".  In the command script itself,  the
command must be implemented with an "Object[]" argument - and it
must be (explicitly) entered into the dictionary mentioned above

The mechanism works fine and turns out to be very handy.

If need be, just drop a note and I'll publish an example.

Kind regards,

Andreas Rozek         Phone:  ++49 (7031) 222305
Bunsenstra?e 80/1     Fax:    -
D-71032 B?blingen     EMail:  [hidden email]
Germany               URL:

SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play:
Beanshell-users mailing list
[hidden email]