get

open operator override fun <T> get(key: Preferences.Key<T>): T?(source)

Get a preference with a key. If the key is not set, returns null.

If T is Set, this returns an unmodifiable set which will throw a runtime exception when mutated. Do not try to mutate the returned set.

Use MutablePreferences.set to change the value of a preference (inside a DataStore.edit block).

Parameters

T

the type of the preference

key

the key for the preference

Throws

ClassCastException

if there is something stored with the same name as key but it cannot be cast to T