E.Kisaragi
05/08/2020, 9:07 PMShawn
05/08/2020, 9:08 PM?. and the scope functionsShawn
05/08/2020, 9:09 PMjava.util.Optional, that is, the only real reason to use it is for java compatibility, afaictShawn
05/08/2020, 9:10 PME.Kisaragi
05/08/2020, 9:11 PMShawn
05/08/2020, 9:16 PMstreetsofboston
05/08/2020, 9:17 PMT? isn’t .Shawn
05/08/2020, 9:22 PMZach Klippenstein (he/him) [MOD]
05/08/2020, 9:33 PMOptional types is they let your type parameter be nullable itself. Otherwise you need to use a null sentinel, which can be awkward.streetsofboston
05/08/2020, 9:45 PMclass MyClass<T : Any?>() {
val optionalValue: T? get() { TODO() }
fun doSomething(callback: (T) -> Any) {
callback(optionalValue)
}
}streetsofboston
05/08/2020, 9:46 PMclass MyClass<T : Any?>() {
val optionalValue: T? get() { TODO() }
fun doSomething(callback: (T) -> Any) {
callback(optionalValue as T)
}
}
I guess there are such things as T?? types? 🙂Mike
05/09/2020, 1:00 AME.Kisaragi
05/09/2020, 3:06 AMstreetsofboston
05/09/2020, 11:34 AMoptionalValue as T, since T has an upper bound of Any? (not Any) and Any? allows for null values... no need for throwing a NoSuchElementException, I just want to send callback a null when the value is null...E.Kisaragi
05/09/2020, 12:45 PM