Preamble: I know to use a list or other collections to return the result, but then I need to go through the list that displays the results: see the second example
Preamble 2: I am looking for an answer outside of "this is not supported in Java ..."
I am looking for a convenient way to return multiple objects from a Java method call.
Like in PHP:
list ($obj1, $obj2, ...) foobar();
I am really tired of passing holders in arguments, for example:
class Holder {
int value;
}
Holder h1=new Holder();
Holder h2=new Holder();
and then:
o.foobar(h1,h2);
... it would be very interesting if someone came up with an elegant way to get around this.
List use
List<String> = foobar();
There are two drawbacks:
I must first pack the List on the side of the called house:
ArrayList<String> result = new ArrayList<String>
result.add("foo");
result.add("bar");
Then on the caller side I have to snatch the results:
// This is on the caller side
List<String> result = foobar();
String result1 = result.get(0);
String result2 = result.get(1); // this is not as elegant as the PHP equivalent
, , , , String, Integer, , ...
.