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