Why can't Kotlin infer the parameter and return type of a function?

Viewed 93

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) }
1 Answers
Related