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

244
Vistas
Are Kotlin functions really first class types?

Does the fact that this doesn't compile mean that they're not quite first class types?

fun foo(s: String): Int = s.length
// This won't compile.
val bar = foo

Is there a way to do this without resorting to OO?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Does the fact that this doesn't compile mean that they're not quite first class types?

No, it doesn't.

In Kotlin, to reference a function or a property as a value, you need to use callable references, but it is just a syntax form for obtaining a value of a function type:

fun foo(s: String): Int = s.length

val bar = ::foo // `bar` now contains a value of a function type `(String) -> Int`

Once you get that value, you are not limited in how you work with it, which is what first-class functions are about.

over 4 years ago · Santiago Trujillo Denunciar

0

You can use reference to the function :::

fun foo(s: String): Int = s.length

val bar = ::foo

And then invoke it:

bar("some string")
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