I expected fun foo(varargs i: Int) to translate to void foo(java.lang.Integer... i), but it translates to void foo(int... i) and indeed the parameter is an IntArray and not an Array<Int>.
Nothing is wrong with this optimization, I just mention it because it slightly suprised me.
The bytecode Kotlin produces is now somewhat unique when you do method overloading.
Since JDK 7 the compiler would not allow you to do this:
void foo(int… i)
void foo(Object… o) // Allowed with JDK 6, ambiguous reference with JDK 7
The reason is simple:
-
The compiler selects the most-specific method when more than one method is applicable.
See http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.2.5 -
But it should not be possible to choose between
foo(int…)
andfoo(Object…)
as neither
int
is a subtype ofObject
, norObject
is a subtype ofint
.
As far as Kotlin and the JVM concerned it is all right to do it of course, so there is not much to talk about.