Ofir Bar
02/12/2020, 12:04 PMDrew Hamilton
02/12/2020, 12:12 PMT
can be a nullable type. In the first one, it can’t be.wcaokaze
02/12/2020, 12:24 PM<T>
means <T : Any?>
Ofir Bar
02/12/2020, 12:27 PM<T>
to behave such as <T: Any>
and to have a null value explicitly use <T: Any?>
@Drew Hamilton @wcaokazeDrew Hamilton
02/12/2020, 12:38 PMAny?
is the lowest common denominator; the most generic available type in the JVM.arekolek
02/12/2020, 12:38 PMT : Any
makes sense:
data class Optional<T : Any>(val value: T? = null)
interface Test {
fun test(): Optional<String?> // compilation error
}
It's a constraint https://kotlinlang.org/docs/tutorials/kotlin-for-py/generics.html#constraints
so it makes sense that without no constraints it is the most general typeOfir Bar
02/12/2020, 12:44 PM