I'm trying to figure out why multiple `vararg` par...
# getting-started
f
I'm trying to figure out why multiple
vararg
parameters are not allowed even if they have different types
l
vararg
must be the last parameter, so, having 2 of them is not possible as only the latter would really be the last one
f
well you can have a parameter after it if you use the named argument syntax
l
Only when calling the function
But you can’t declare a function having 2 varargs
f
right, but I am wondering why that is
Maybe I am missing something
I understand why its necessary when both varargs have the same type or one is a supertype
but I could pass
1, 2, 3, "bla", "blubb"
to a function with an
Int
and a
String
vararg
r
Because "different types" doesn't mean much. For example:
Copy code
interface A
interface B
class AI : A
class BI : B
class AB : A, B
fun x(vararg a: A, vararg b: B) { ... }
x(AI(), AB(), BI())
Where is the division line? That's a simple example. It can get far more complicated, and that's even without taking things like generics into account.
f
sure but couldn't it still be supported for types where it doesn't lead to ambiguity?
just a theoretical question
r
Not in a way that wouldn't lead to all sorts of confusion and edge cases.
f
I see, thanks