Kotlin Construtor Trigger Kotlin Property Setter

June 28, 2019
class User(id: String? = null) {
    var isActive: Boolean = false

    // using this won't trigger setter
    // var id: String? = id

    var id: String? = null
        set(value) {
            field = value
            isActive = value != null
        }

    init {
        if (id != null) {
            this.id = id // trigger setter
        }
    }
}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.