Skip to main content

It would also be awesome if we were able to use Covariance with Generics, for example, declare a type based on interface and use based on implementation:

MyList<SomeInterface> myListExample = new MyList<SomeInterface>();

SomeImplementation myImplementation = new SomeImplementation();

// This currently fails to compile

myListExample.add(myImplementation);

2 answers
  1. Mar 21, 2023, 4:24 PM

    I may have mixed, and the List class is not the best example.

    I want to create a class that receives a type T which I can set as Fruit and then add Apple and Banana instances.

    Again, my expectations are towards .NET implementation but without its quirks.

0/9000