Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda