Avatar ·

What does the `::` operator mean in Kotlin? Explain with examples

Hi everyone! I just started learning Kotlin for Android development and came across a strange syntax with two colons `::`. I encounter it everywhere: in lambdas, when working with reflection, in Jetpack Compose. \n\nFor example, I saw this code:\n```kotlin\nval onClick: (View) -> Unit = ::handleClick\n```\nOr this:\n```kotlin\nclass MyFragment : Fragment() {\n private val binding by viewModels()\n // ...\n val items = listOf("A", "B", "C")\n val filtered = items.filter(String::isNotEmpty)\n}\n```\nAnd also in Compose:\n```kotlin\nButton(onClick = ::onButtonClick) { Text("Click") }\n```\n\nI understand that this is somehow related to references to functions or properties, but I can't grasp the difference between `::handleClick` and just `{ handleClick(it) }`. Why is this operator needed? When should I use it, and when should I not?