```fun <T: Any?> a(b: (value: T) -> Unit)...
# getting-started
m
Copy code
fun <T: Any?> a(b: (value: T) -> Unit) {
    b(null)
}
why does this not work? Why does it say T is non-nullable, even though it uses
Any?
? Can I make this work without changing the lambda param to
value: T?
?
e
T : Any?
includes
T : Any
. if you want to always allow
null
, you need
T?
(so changing the type of your lambda, yes)
m
Oh you are right now I get it, thank you 😅
s
Maybe you’re expecting it to work more like a
List<T>
, but remember that list elements have
out
variance whereas function parameters have
in
variance. So a
List<T>
is a
List<T?>
, but a
(T) -> Unit
is not a
(T?) -> Unit
.