You can create a function that maintains the nullability of the parameter, on the return type if the parameter and the return type are the same.
See this example:
fun <T : String?> foo(bar: T): T = TODO()
For this function the return type relates to the parameter type like this:
Parameter type | Return type |
---|---|
String | String |
String? | String? |
Now my question is if it is possible to do the same thing but with the parameter type and the return type being different.
Something like this:
Parameter type | Return type |
---|---|
String | Int |
String? | Int? |
Thanks in advance.