snrostov
01/04/2018, 12:19 PMGT
cannot be inferred?
class A<T>(val t: T)
class B<T, out U: A<T>>(val t: T, val at: U)
fun <T> B<T, *>.withCapturedU(): B<T, A<T>> = this
private fun <FT> f(x: B<FT, *>) {
g(x) // ERROR, why?
g(x.withCapturedU()) // OK
}
private fun <GT> g(y: B<GT, A<GT>>) {
println(y)
}
Andreas Sinz
01/04/2018, 3:00 PM*
seems to put the compiler off. if I change it to x: B<FT, A<FT>
it works fine*
, but rather the variance of your generics, if you define T
inside A
and B
as out
, it works finesnrostov
01/04/2018, 5:17 PMAndreas Sinz
01/04/2018, 6:14 PM*
can be A<FT>
or any subclass of A<FT>
together with FT
being invariant means the compiler is not able to ensure that you'll always have A<GT>
inside your B<GT, *>
. not sure about the red highlightingsnrostov
01/05/2018, 10:33 AM