I really hopped that Kotlin will have elegant support for multiple return type functions. Tupples (now deprecated) and data classes seem more like workarounds/hacks, similar to using wrapper class in java.
Pair and Triple are very usefull classes that can be used for this, but in esence thats just built in kind of wrapper class, isn't it? It's still single return value.

Couldn’t kotlin automatically convert the returned tuple into a data class with component1, component2, etc and return that? This would work so great together with Destructuring Declarations and solve such an age old problem in programming.

I recently faced this problem in Java where a new point with x,y has to be returned by a function executed inside a draw() method. The disaster in Java is that returning a new Point object that only contains x and y numbers allocates quite some memory that is discarded after the method returns and there are many of these points created on each frame. A lot of memory allocations not needed for simply returning two values of the same type.

It will be much more efficient if Kotlin could recognize a tuple of the same type and create the most optimal data structure (plain old array?) to pass the values, so no extra memory than needed is allocated for the return values.

Is the current boxing/unboxing of return values in Kotlin memory efficient?

I don’t think a tuple is more efficient than an Array but I though an Array would be more efficient than an object, apparently, that’s not the case. Why I’m pointing out is that all of them are less efficient than returning the values because, in addition to the size of the values you return from a method, the wrapper object always has some memory overhead.

Yes not having a wrapper object is more efficient but such operations must first be supported by bytecode, which I don’t think it is. Project Valhalla might help there. There isn’t a good representation in Java either so that will always lead to incompatible code.

So if you really need performance now you can either cache and reuse your objects/tuples or in case of your point example pack two ints in one long.

You’re right bytecode does not support return of more than one value (there are type specific return instructions - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.11.8). Value types may provide (limited) relief. At the same time, there is nothing stopping the JVM from deciding to allocate your temporary on the stack and just returning it that way - the JVM can do whatever it wants as long as it preserves the semantics of the code. In fact, for a temporary the analysis needed to be able to do it would be rather simple, so something likely to be optimized (you’d have to look at the generated machine code to be sure).

Multiple return values is the one feature of Groovy that I really miss when I switch from working in Groovy for a bit back to Java. It allows returning arbitrary types in a List and then provides syntactic sugar for assigning the List values to variables