https://kotlinlang.org logo
Title
u

user

06/28/2022, 12:51 AM
Why can't you change a property value permanently in kotlin? Here's the code: class Person(var firstName: String, var lastName: String) { var fullName: String = firstName + lastName fun fullName() = firstName + lastName override fun toString(): String { return fullName() } } fun main(){ val test = Person("test", "fortest1") test.lastName = "fortest2" println(test.fullName) } The result will only be testfortest1. It looks like you are working with a copy of test once test is created.