``` inline operator fun <reified V : Any> Sh...
# announcements
v
Copy code
inline operator fun <reified V : Any> SharedPreferences.getValue(thisRef: Any?, property: KProperty<*>): V {
  return getValue(thisRef, property, V::class.java)
}

fun <V> SharedPreferences.getValue(thisRef: Any?, property: KProperty<*>, clazz: Class<V>): V {
  return clazz.cast(when (clazz) {
    String::class -> getString(name, "") as V
    Int::class -> getInt(name, 0) as V
    Float::class -> getFloat(name, 0F) as V
    Long::class -> getLong(name, 0L) as V
    Boolean::class -> getBoolean(name, false) as V
    else -> throw IllegalArgumentException("This Type[${V::class.java.simpleName} is not supported by SharedPreferences")
  })
}