Answer the question
In order to leave comments, you need to log in
Explain what is going on in the code block?
What is the use of :: in the second line? I know that in Java it is a reference to a static method in a lambda. Shorter syntax. What is this used for in Kotlin?
Answer the question
In order to leave comments, you need to log in
This notation is similar to
takeIf { it.isNotEmpty() }
Colon in Kotlin means getting a reference to a function/property. The List::isEmpty line in particular returns a reference of type (List<Int>) -> Boolean
. The takeIf argument is a function type (T) -> Boolean, in this case List<Int> -> Boolean
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question