Why can the code be compiled when I add a redundant comma in parameter?



I use Android Studio Arctic Fox, the Code A is from the project.

And Code A is can be compiled correctly. I find that Code B can also be compiled creeclty when I add a redundant comma in parameter list, why?

Code A

composable(Bills.name) {
            BillsBody(bills = UserData.bills)

Code B

composable(Bills.name, ) {
            BillsBody(bills = UserData.bills)

The same

public fun NavGraphBuilder.composable(
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    content: @Composable (NavBackStackEntry) -> Unit
) {
        ComposeNavigator.Destination(provider[ComposeNavigator::class], content).apply {
            this.route = route
            arguments.forEach { (argumentName, argument) ->
                addArgument(argumentName, argument)
            deepLinks.forEach { deepLink ->


This is called trailing comma and was added in Kotlin version 1.4.

One of the main reasons behind trailing commas – using them reduces the amount of lines you need to update when the list length changes. Makes commits a bit cleaner.

Answered By – Yuri Sh

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More