rishabhsinghbisht
05/17/2019, 12:08 PMkarelpeeters
05/17/2019, 12:12 PMreified
you can do null is T
.tseisel
05/17/2019, 12:12 PMfun <T : Any> withNonNull(foo: T)
rishabhsinghbisht
05/17/2019, 12:17 PMtseisel
05/17/2019, 12:19 PMrishabhsinghbisht
05/17/2019, 12:23 PMprivate infix fun <Key, T, Value, Return : Value> <http://Key.at|Key.at>(map: MutableMap<Key, Value>): ReadWriteProperty<T, Return?> {
return object : ReadWriteProperty<T, Return?> {
override fun setValue(thisRef: T, property: KProperty<*>, value: Return?) {
if (value != null) { // should be only done if Value is non nullable type
map[this@at] = value
}
}
override fun getValue(thisRef: T, property: KProperty<*>) = map[this@at] as Return?
}
}
rishabhsinghbisht
05/17/2019, 12:24 PMvar value: String? by PROPERTY_KEY at mutableMap
karelpeeters
05/17/2019, 12:42 PMrishabhsinghbisht
05/17/2019, 2:23 PMrishabhsinghbisht
05/17/2019, 2:24 PMkarelpeeters
05/17/2019, 2:26 PMrishabhsinghbisht
05/17/2019, 2:29 PMValue
is non nullable type.
(updated on file above)karelpeeters
05/17/2019, 2:33 PMrishabhsinghbisht
05/17/2019, 2:33 PMa
using this delegate.
a = null
should update value in map if map has nullable type, but if map is non nullable this should just ignore it.rishabhsinghbisht
05/18/2019, 10:14 AMmap[key] = null
, but instead i can do map.remove(key)