get

inline operator fun <T> Preferences.get(key: String): T?

Retrieves a value of T type from the Preferences for the given key.

If the T type is not String, Boolean, Int, Float, Double or Long then it is assumed that the value is stored as a JSON string and deserialized using the Json module.

A new Json instance is created for each deserialized value. If the preference is read frequently and excessive object creation might be a concern, consider manual deserialization and retrieving the value as a String.

Note that Preferences do not support Double values. Instead, a Float is read from the Preferences and converted to Double. Consider using a JSON-serializable object if you need to store Double values with high precision.

Will return null if the key is absent in the Preferences.


inline operator fun <T> Preferences.get(key: String, defaultValue: T): T

Retrieves a value of T type from the Preferences for the given key or returns the defaultValue if the key is absent.

If the T type is not String, Boolean, Int, Float, Double or Long then it is assumed that the value is stored as a JSON string and deserialized using the Json module.

A new Json instance is created for each deserialized value. If the preference is read frequently and excessive object creation might be a concern, consider manual deserialization and retrieving the value as a String.

Note that Preferences do not support Double values. Instead, a Float is read from the Preferences and converted to Double. Consider using a JSON-serializable object if you need to store Double values with high precision.