Re: Variable args feature
Harish Krishnaswamy <[email protected]>
| Newsgroups | gmane.comp.java.beanshell.devel |
|---|---|
| Message-ID | <[email protected]> |
This is exactly what I have done; feels good to be validated.
Thanks,
Harish
Pat wrote:
>On Sat, May 22, 2004 at 10:27:45PM -0400, Harish Krishnaswamy wrote:
>
>
>>Is it possible to create methods with variable arguments at the moment?
>>
>>
>
>While there is currently no explicit varargs syntax, you could use the invoke()
>meta-method to create the effect of variable argument lists for a method. For
>example:
>
> // invoke() is called whenever an undefined method is invoked
> invoke( String name, Object [] args ) {
> if ( name.equals("foo") )
> return fooVarargs( args );
> }
>
> // The variable argument version of the method takes Object []
> fooVarargs( Object [] args ) { print( args ); }
>
> // Invoke foo() with arbitrary number or type of arguments
> foo( 1 );
> foo( 1, 2 );
> foo( 1, 2, 3 );
> // etc.
>
>
>Pat
>
>
>
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click