Is it possible to call `fun foo` in <this runnable...
# getting-started
e
Is it possible to call
fun foo
in this runnable example in a way that doesn't provide a value for the first parameter with a default value? The types of the first two parameters happen to be compatible, which is unfortunate (even though they're not the same!)
This is a possible solution But it's not very nice to have to manually instantiate an array. It beats the purpose of using
vararg
y
https://pl.kotl.in/BIUoXKVQ_ Edit: sorry that's the same solution you posted :) I was a minute too late
e
Thanks, I think it's similar (or the same) as what I did
I guess there's no way around it?
y
I don't think there's a way to make it work even for non-lambda arguments. I'm on mobile so the playground editing experience is horrible, but try the same function where
optionalParameter
is a Long and the other varargs as Int, it should be a comparable situation
e
Yeah, probably it is
d
Copy code
foo(
    optionalParameter = {},
    { println("I want to be the first extra parameter, but I'm the optional parameter") },
    { println("Another one") },
    { println("Yet another one") },
)
e
Thanks. I guess this is the most concise syntax possible, but still requires a change at the call site
More info: see this thread and this issue. Let's not continue the discussion here, but there.