Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda