Why do these things compile differently?


private inline fun findFixpoint(f: (Double) -> Double): Double {   var x = 1.0   while (true) {   val y = f(x)   if (x == y) return y   x = y   } }

val cosfix1 = findFixpoint { Math.cos(it) }

val cosfix1 = findFixpoint(Math::cos)

The first call compiles down to what you’d expect (tight code), the second performs invocations of the function via helper classes and so on. But my understanding of the Kotlin syntax is that both forms mean the same thing, so why do they compile differently? Is this just a lacking bit of smartness in the compiler or is there some deeper reason?


The double colon notation is reserved for creating reflection objects. Soon the functions you get via "::" will be equipped with reflection features (get name, owner, type, etc.).

Of course, in your case reflection features are not used, so you’re right, we could have inlined this without any harm.