I know it sounds stupid, but following are 2 scena...
# android
o
I know it sounds stupid, but following are 2 scenarios. I wonder why the compiler complain about 1) but on 2) there is nothing? Obviously on 2), T can't be null
c
In the first case, the compiler knows the type of
hey
, because you declared it to be
String
(non-null). In the second example, the type parameter could be anything, including a nullable type.
val s: String? = null; s.doOrLog()
is valid, type type parameter is just
String?
instead of
String
. You’d have to give the type parameter a bound of
T : Any
to declare that the type parameter should be non-nullable
🍻 1
o
Ohhhh got it, totally makes sense now, thanks mate! @Casey Brooks