|
From: Samuele P. <pe...@in...> - 2001-08-19 01:22:45
|
Hi.
> Subject:Indefinite number of functional arguments
>
>
> Question:
>
>
> The statement (e.g.)
>
> def functionName ( arg1, *otherArgs)
>
> is really useful sometimes and has no real equivalent in java.
> Tried (with no success) all the ways I can think of to convert this to
> (e.g.)
>
> public String functionName( java.lang.String arg1,
> java.lang.String [] otherArgs )
>
> Does anyone have any suggestions?
That's really the typical java idiom to achieve that:
... meth(...,<a-specific-type>[] rest)
... meth(...,Object[] rest)
and at call site:
anObj.meth(..., new <your-type>[] {expr,....} )
but if also at call site your rest argument should be programmatically
constructed (they number is known at runtime only)
you can use either a Vector or an ArrayList (with Java2):
java.util.ArrayList rest = new java.util.ArrayList();
... fill up rest
meth.func(...,rest.toArray(new <your-type>[0]))
if <your-type> is Object, then the parameter-less version of toArray is fine.
Depending on some trade-offs you could use ArrayList(Vector) instead of the
array type in meth signature.
More a Java FAQ than a jython one <wink>.
regards, Samuele Pedroni
|