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
str1andstr3properties are assigned on creation ofStringFactory.Companionand never change their value.In
str2the property will get the value fromuserSettingsanytime you access it. There's no field for storing that value. It basically behaves the same asgetUserKey().