3 ms·
The logic behind Java is that the language should not concern itself with technicalities, the JVM will take care of it. This principle goes both ways, the JVM c
by Arwill 9y ago
The logic behind Java is that the language should not concern itself with technicalities, the JVM will take care of it. This principle goes both ways, the JVM can't optimize your code if you have already decided how it should behave. As i understood, that is why they never added the more technical features as MS did in C#. In principle if you want to return multiple values from a method, you can return them in an array, and in principle the JVM optimizer will take care of the array. That is in principle, i don't know how good the optimizer got in this regard.
But i still prefer Java for simplicity and readability.
- 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
- olavk 9y agoOptimization is not the issue. It is not possible in a strongly typed language to return multiple heterogeneous values in an array. That is why we have tuples.