https://kotlinlang.org logo
#announcements
Title
# announcements
j

joelpedraza

07/11/2017, 4:10 PM
Is any way to ensure calls to fun stored as a (val) class field are inlined? For example to pass in a comparator to a heap structure.
d

diesieben07

07/11/2017, 4:14 PM
joelpedraza: Not sure what exactly you want to inline, could you post an example?
k

karelpeeters

07/11/2017, 4:21 PM
I think he wants to pass a funtion as a parameter to a class and then inline that in all of the methods of that class.
@joelpedraza No this is not possible, the passed funtion is not known at compile time. The JVM can sometimes inline things like this, so performance shouldn't be that bad.
j

joelpedraza

07/11/2017, 5:12 PM
@karelpeeters In my microbenchmarks runtime was 4x slower, but yes I'm essentially looking for a way to inline a field, it would be possible if the fun was statically compiled
d

diesieben07

07/11/2017, 5:38 PM
If it was statically known, you wouldn't need a field 😉