how to make a function with one input parameter wh...
# getting-started
p
how to make a function with one input parameter which returns the same type but retains nullability in a generic way? e.g.
T -> T
and
T? -> T?
e
The default upper bound of generics is
T?
so if your function is
fun <T> foo(bar: T): T
and you call it as
foo<Int?>(3)
the return type will be of type
Int?
.
p
what if the function shuold onlly accept
Int
and
Int?
?
e
Declare it as
fun <T : Int?> ...
p
thanks!
👍 1