Suppose you have 2 Kotlin classes
class Battery(
val carbon: Any,
val zinc: Any
)
class RemoteControl(
/* inline */ val battery: Battery,
val buttons: Any
)
Notice the commented out inline
keyword in RemoteControl
. Uncommenting it doesn't produce an error in Intellij.
Is this valid Kotlin code and what does it do?
My expectations is that it is equivalent to
class RemoteControl(
val carbon: Any,
val zinc: Any,
val buttons: Any
)
But it doesn't appear to do anything.
I'm using Kotlin 1.3.72 and Android Studio 4.0.1
The
inline
modifier can be used on the property (on the property of primary constructor as well):In such a case, all accessors are marked inline automatically. At the call site the accessors are inlined as normal functions.
Applying inline to a property that has a backing field, or its accessor, results in a compile-time error:
There is more info.