chrisjenx
03/31/2016, 7:22 PMjava.lang.IllegalArgumentException: This Type[java.lang.String] is not supported by SharedPreferences
regardless of the type:
inline operator fun <reified V : Any> SharedPreferences.getValue(thisRef: Any?, property: KProperty<*>): V {
return getValue(thisRef, property, V::class.java)
}
@Suppress("UNCHECKED_CAST")
fun <V> SharedPreferences.getValue(thisRef: Any?, property: KProperty<*>, clazz: Class<V>): V {
val name = property.name(thisRef)
return 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[${clazz.name}] is not supported by SharedPreferences")
}
}
Am I missing anything?