alexreidy
06/05/2017, 3:59 PMval square: (Int) -> Int = { it * it }
val transforms = listOf(square, { it }, { it * 2 }, { 1 })
inline fun printNumbers(transform: (Int) -> Int) {
for (i in 1..10) println(transform(i))
}
printNumbers(transforms.getRandomElement())
I'd be frightened if the compiler could figure out how to inline the transform in this case. So I guess what I wonder is when does inlining actually take place? Should I read inline as "inline if possible"? Or "inline if the function argument is a lambda literal"? Or "inline if the transform argument is effectively final"?
The following would inline to println(i*i), right? But what if I made square a var?
printNumbers(square)