Referencing a function

suggest change

Functions are first-class citizens in Kotlin. You can obtain a reference on it using double colons and then pass it to another function:

fun isPositive(x: Int) = x > 0

val numbers = listOf(-2, -1, 0, 1, 2)
println(numbers.filter(::isPositive)) // [1, 2]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents