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
) {
addDestination(
ComposeNavigator.Destination(provider[ComposeNavigator::class], content).apply {
this.route = route
arguments.forEach { (argumentName, argument) ->
addArgument(argumentName, argument)
}
deepLinks.forEach { deepLink ->
addDeepLink(deepLink)
}
}
)
}
CodePudding user response:
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.