It must be stupid question, but I'm really new to Kotlin and I didn't find any solution.
How to declare class field? Like we can have it in java:
protected SharedPreferences mSharedPreferences;
And later in onCreate()
:
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
Now I can use it anywhere I want (in subclasses of this base activity).
I try to do same in Kotlin:
protected var sharedPreferences : SharedPreferences
And in onCreate()
:
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
But I get a warning: "Property must be initialized or be abstract"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…