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 件の回答
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.