no, it doesn't. Nothing to do with vararg, it seem...
# announcements
h
no, it doesn't. Nothing to do with vararg, it seems.
Copy code
fun foo(bool: Boolean = true, string1: String) {}
fun main(args: Array<String>) {
   foo("b") // does not compile
}
k
Then that's probably how the rules of default parameters work. Doesn't look like there's an explanation on the site.
h
yeah, it seems default values have to be "to the right" of given parameters (which makes sense, if you think that the types could be the same)
h
but this doesn't compile as well:
Copy code
fun foo(vararg strings: String, bool: Boolean = true) {}

fun main(args: Array<String>) {
    foo("a", "b", true) // does not compile
}
k
Yea that never works, you can't have anything after varargs.
h
so you can't mix vararg and default?
k
Well you can if you put the defaults before the vararg.
h
my bad, sorry
foo("a", "b", bool = true)
works, like documented
k
I think they disallow normal parameters after vararg because typing wouldn't work that well.
h
putting the default before the vararg was my initial example, @karelpeeters
k
Yea I meant in the function definition, then you can use a default parameter without naming it at the callsite.
h
like how?
k
Ah my bad, that doesn't work either.