Why plus operator between two shorts returns an Int

Viewed 135

I'm working on a program which run on machines with limited resources. I must optimize as much as I can the memory usage.

To do so, I set Short type in parameter of different functions, but then, I noticed at one point that my variables which are Short, give an Int when I use the '+' operator.

From Primitive.kt: public operator fun plus(other: Short): Int

Why does it return an Int rather than a short ?

Does the JVM optimize the code behind the scene ?

If i use massively the toShort function, will this slow my code ?

0 Answers
Related