August 2017
Intermediate to advanced
440 pages
10h
English
We can optimize property calls by using the inline modifier. During compilation, each property call will be optimized. Instead of really calling a property, the call will be replaced with the property body:
inline val now: Long
get() {
println("Time retrieved")
return System.currentTimeMillis()
}
With inline properties, we are using the inline modifier. The preceding code will be compiled to the following:
println("Time retrieved")
System.currentTimeMillis()
Inlining improves performance because there is no need to create additional objects. No getter will be invoked because the body replaces the property usage. Inlining has only one limitation--it can be applied to properties that do not have a backing field.
Read now
Unlock full access