I have : `interface A<T>` I want to write a...
# announcements
c
I have :
interface A<T>
I want to write a function that takes an
A
and a value of the same type. Intuitively, this would look like:
fun <T> foo(a: A<T>, v: T)
The problem is that if I call it this way:
Copy code
val a: A<String> = ...
val v: Int = ...
foo(a, v)
It calls
foo<Any>(a, v)
, but I want it to call
foo<String>(a, v)
(and fail, because `v`'s type doesn't match what was expected by
a
). This function is fairly simple, so solutions using
reified
or other
inline
mechanism are not a problem, but I don't see how to do it.
a
In fact, the provided code fails as expected. https://pl.kotl.in/8mGpmWyFm
Type mismatch: inferred type is Int but String was expected