When will these string get their value and should they all produce the same value?
class StringFactory{
companion object{
val str1 = App.shared.userSettings.getString(key, "")
val str2: String
get(){
return App.shared.userSettings.getString(key, "")
}
val str3 = getUserKey()
fun getUserKey():String {
return App.shared.userSettings.getString(key, "")
}
}
}
When will these change their value? When the code compiles, when I read them or at some other time?
The
str1
andstr3
properties are assigned on creation ofStringFactory.Companion
and never change their value.In
str2
the property will get the value fromuserSettings
anytime you access it. There's no field for storing that value. It basically behaves the same asgetUserKey()
.