https://kotlinlang.org logo
Title
h

Hexa

03/17/2019, 9:19 AM
Would the
getProperty
function in this case be best declared
inline
?
fun main() {
    val someHashMap = mapOf("first" to Account1("test", "1234"))
    println(getProperty("first") {someHashMap.getValue(it).number})
}

fun getProperty(name: String, action: (String) -> String) : String{
    return action(name)
}

class Account1(val name: String, val number: String)
I checked the decompiled Java bytecode but I can't work out why inline is better? Is it because in the
none-inline
it calls the
getProperty
function in the
main
like in here? https://gist.github.com/rinnegan/4233b6a242b5f2864e0737b186b45df7#file-inline-vs-none-inline-L33
k

karelpeeters

03/17/2019, 9:41 AM
In the non-inline one there's an instance of
Function
created for every call, in the inline one that isn't necessary.
h

Hexa

03/17/2019, 10:02 AM
ah did you mean this call
(Function1)(new Function1()
?
thanks @karelpeeters
k

karelpeeters

03/17/2019, 10:58 AM
Yes, that's what I mean. You're welcome!