i was trying to change the value externally here i...
# getting-started
a
i was trying to change the value externally here is my code
class SettingMyValue{           var setLength = 9 }
and from external kt file i put this code
SettingMyValue().setLength = 7
to reassign the value of
setLength
externally but it return 9 but all i want was to print the reassigned value (7) and if there is no external change returns 9
k
SettingMyValue()
creates a new object. Each object will have it's own
setLength
variable. Maybe you want
object SettingMyValue
? If that doesn't work, you could add it to the
companion object
instead.
a
i try with object and even companion object it return the same
k
Could you give more complete code?
(click the lightningbolt and then "create code or text snippet". ideally switch the language to kotlin)