vibin
11/06/2018, 2:46 PMVladyslav Sitalo
11/06/2018, 2:48 PMinitialValue: T?
vibin
11/06/2018, 2:49 PMvibin
11/06/2018, 2:50 PMObservableField("").get()
returns non-null type, but ObservableField(null).get()
returns nullable typevibin
11/06/2018, 2:50 PMdalexander
11/06/2018, 2:55 PMfun main() {
val d1 = Demo<String>("asdf")
val d2 = Demo<String?>(null)
onlyAcceptsNonNullableStrings(d1.getItem())
// onlyAcceptsNonNullableStrings(d2.getItem()) // This is a compiler error
}
fun onlyAcceptsNonNullableStrings(value: String) {
//do whatever
}
class Demo<T>(private val item: T) {
fun getItem(): T {
return item
}
}
Maybe remove the upper bound from your class definition?Shawn
11/06/2018, 2:56 PMShawn
11/06/2018, 2:56 PMObservableField<String>()
, how does that work?Shawn
11/06/2018, 2:57 PMthis(null)
if T
is String
dalexander
11/06/2018, 2:57 PMAny
is kind of a subclass of Any?
so that’s not always going to be a legal call, because T could be non-nullable.dalexander
11/06/2018, 2:59 PMDico
11/06/2018, 3:04 PMvibin
11/06/2018, 3:06 PMdsavvinov
11/06/2018, 3:46 PMDico
11/06/2018, 5:38 PMdsavvinov
11/06/2018, 7:11 PMilya.gorbunov
11/07/2018, 2:07 AMvibin
11/08/2018, 8:11 AM