3 ms·
> In principle if you want to return multiple values from a method, you can return them in an array This is not viable. If I want to return e.g. an (error) cod
by dtech 9y ago
> In principle if you want to return multiple values from a method, you can return them in an array
This is not viable. If I want to return e.g. an (error) code and string, the only Array you can put that in is an array of the root type (Object), losing all type-safety.
In C# and Scala multiple return values use a Tuple class, with some syntactic sugar to easy create and read them. It will eventually be in Java [1], it just takes decades.
It also has very little to do with the optimizer, there's not reason why the JVM couldn't support & optimize it.
[1] http://openjdk.java.net/jeps/305 http://openjdk.java.net/jeps/305