Mixing named and positional arguments

With the introduction of Kotlin 1.3.70 (currently in EAP), it’s now possible to mix named and positional arguments even better. Before 1.3.70, it was possible use named arguments in the following way:

fun main(args: Array<String>) {
    // This is valid mixing of positional and named arguments
    watch("Lord of the Rings", autoplay = true, volume = 80) 
}

fun watch(movie: String, autoplay: Boolean, volume: Int) {}

However, what was not possible, is to mix positional arguments after named arguments, like this:

fun main(args: Array<String>) {
    // Not valid before 1.3.70, but is valid since 1.3.70.
    watch("Lord of the Rings", autoplay = true, 80) 
}

fun watch(movie: String, autoplay: Boolean, volume: Int) {}

For more information about this syntax enhancements see the Youtrack issue.

One Reply to “Mixing named and positional arguments”

Leave a Reply

Your email address will not be published. Required fields are marked *