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

290
Visualizações
How do you define an array of funs(functions) in Kotlin?

How do you define an array of funs(functions) in Kotlin?

This is my assumption of how it would be done...

this.funs = arrayOf : Unit(
    this::openCamera,
    this::sendSMS,
    this::makeCall
        )

How would I invoke each array item as a function at runtime? Would simply specifying 'funs' in place of either openCamera(), sendSMS(), and MakeCall() in a forEach() loop work?

or.. is this the way that I would invoke each function:

val function = getFunction(funs)
function() 
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you had some functions defined as

fun one()   { print("ONE") }
fun two()   { print("TWO") }
fun three() { print("THREE") }

Then you can create an array of these as

fun someFun(){
    val arrayOfFunctions: Array<() -> Unit> = arrayOf(::one, ::two, ::three)
    arrayOfFunctions.forEach { function ->
       function()
    }
}
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