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

289
Views
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 answers
Answer question

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 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!