The Code A is from the end branch of the official sample project.
I think I can simplify it, so I write Code B and Code C, but in fact, they are wrong, why?
BTW, Code D can be compiled.
Code A
val onPeopleChanged: (Int) -> Unit = { viewModel.updatePeople(it) }
Code B
val onPeopleChanged = { viewModel.updatePeople(it) }
Code C
val onPeopleChanged = {it -> viewModel.updatePeople(it) }
Code D
val onPeopleChanged = {it:Int -> viewModel.updatePeople(it) }
From the official documentation it seems that Kotlin cannot infer the types in the lambda expression: refer to example 4 here https://play.kotlinlang.org/byExample/04_functional/02_Lambdas