I
I
Igor-Novikov2020-06-07 16:05:16
Kotlin
Igor-Novikov, 2020-06-07 16:05:16

Explain what is going on in the code block?

5edce517e3ff4289869088.png

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

1 answer(s)
K
koperagen, 2020-06-07
@koperagen

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 question

Ask a Question

731 491 924 answers to any question