andylamax
07/03/2020, 10:32 AMfun <T> Foo()
and fun <T:Any> Foo()
?
So far I have just been using IntelliSense suggestions. I wan't to understand more. Any deep explanation?diesieben07
07/03/2020, 10:33 AMString?
) for T
, the 2nd one does not.araqnid
07/03/2020, 10:33 AMT: Any
specifies that T is a non-null type (Any?
is the ultimate supertype)andylamax
07/03/2020, 10:34 AMfun <T:Any?> Foo()
and fun <T> Foo()
?araqnid
07/03/2020, 10:35 AM<T>
is effectively <T:Any?>
andylamax
07/03/2020, 10:36 AMMd Sajid Shahriar
07/03/2020, 10:45 AMfun <T:Any> foo(t:T)
public final void foo(@NotNull Object t) {
Intrinsics.checkParameterIsNotNull(t, "t");
}
fun <T:Any?> foo(t:T)
public final void foo(Object t) {
}
fun <T> foo(t:T)
public final void foo(Object t) {
}
fun <T> foo(t:T?)
public final void foo(@Nullable Object t) {
}
So yeah to the compiler is basically the same for <T:Any?>
and <T>