Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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) }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!