I noticed that Kotlin create setter for var, and set value via setter instead of set it directly. Can we make setter inline? or set value directly without create private setter method by default?
lateinit var name: String
private set
I noticed that Kotlin create setter for var, and set value via setter instead of set it directly. Can we make setter inline? or set value directly without create private setter method by default?
lateinit var name: String
private set
You can annotate value with @JvmField
annotation to instruct kotlin compiler to not generate a getter/setter pair for it:
@JvmField
private var name: String = "Joshua"
Also, for vals, if you have a private val
, compiler won't generate a getter for it and produce a bytecode which would have it as an ordinary field.