3

I'm trying to understand why i'm getting error in the following code:

class A <T> {}
class B {}
class C : B {}

let a = A<C>() as A<B>

While this line of code is working:

let b = C() as B
Rivka Schwartz
  • 524
  • 5
  • 15
  • The key message from the linked answer is *"arbitrary generic types are invariant"*. The answer itself links to https://stackoverflow.com/a/38591285/2442804 which gives a pretty clear example why your code must not work. – luk2302 Jul 31 '17 at 08:10

0 Answers0