Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

static anonymous array as parameter

807605Aug 24 2007 — edited Aug 24 2007
I have a peculiar situation where I'd like to pass a "static anonymous array" as a parameter.

For example, the function being called would look like this:
public void writeField(String[][] fielddata) { ... }
And the caller would look like this:
...
writeField( {{"id1", "name1", "label1"}, {"id2", "name2", "label2"}});
...
I can easily do this and it works:
...
writeField( new String[][]{{"id1", "name1", "label1"}, {"id2", "name2", "label2"}});
...
But I'd like to avoid the "new" calls if possible.

I'm sure you're thinking, "why?" It's an unusual situation and this really is an ideal way of solving it so please spare me the OO and type safety lesson.

Does anyone know of a way to pass a "static anonymous array" as a parameter. You can pass a static anonymous String, so why not an array? It seems like the compiler could pick up the array data type from the parameter specification of the called function.

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2007
Added on Aug 24 2007
15 comments
248 views