Why casting 'some value typed with type argument' ...
# getting-started
l
Why casting 'some value typed with type argument' does not cause that type to be smartcast? For example, when you have simple function,
Copy code
fun <T> test(value: T): T {
    value as Int
    return 123
}
Shouldn't this work?
Note:
value
is smartcast into
Int
, but
T
is not. The error on
123
says
The integer literal does not conform to the expected type T
.
a
The cast ensures T is Int, but doesn't ensure Int is T.
l
Thanks, that makes sense.