Yes it is: On the JVM you cannot have method overloads for both a vararg and an array parameter of the same type. There can be only 1 of these, but you are free to choose the notation.
Kotlin does not have this restriction, so it can have three functions with the same name and parameter types: vararg, array and list. But because the JVM does not support it, you have to use the solution with @JvmName
that @abond suggested above.
You might feel that the Java is less restrictive than Kotlin, but Kotlin tries to prevent the subtle bugs that can occur when you allow passing an array of Object
where a series of Object
values are expected. Java has warnings to notify you of possibly incorrect code. Kotlin does not need those.
I think this:
fun acceptsAnys(vararg anys: Any) { ... }
val strings = arrayOf("foo", "bar")
acceptsAnys(strings) // Invokes with 1 parameter: an array of strings
acceptsAnys(*strings) // Invokes with 2 parameters: "foo" and "bar". I understand that
// it can be 0 or more parameters because I explicitly told the compiler I want
// it that way
Is a lot clearer than:
void acceptsObjects(Object... objects) { ... }
String[] strings = new String[] { "foo", "bar"};
acceptsObjects((Object)strings); // Invokes with 1 parameter: an array of strings. What?
// Why do I have to add this weird cast?
acceptsObjects(strings); // Invokes with 2 parameters: "foo" and "bar". What? But I pass
// exactly 1 object, which happens to be an array, and now Java converts that
// array to the elements it contains and passes those