5 ms·
Sure, good interface design can ease things, but it doesn't really solve the problem I'm talking about. In Java, List<Foo> and List<Bar> are the same interface
by lazulicurio 7y ago
Sure, good interface design can ease things, but it doesn't really solve the problem I'm talking about.
In Java, List<Foo> and List<Bar> are the same interface. In C#, IList<Foo> and IList<Bar> are different interfaces that just happen to have similar properties/methods.
This means, in Java you can do
Object obj = ...
List<?> lst = (List<?>) obj
Object item = lst.get(3)
Whereas, in C#, to do something similar, you have to dynamically compile at runtime a specialization of a generic delegate.
- jimmaswell 7y agoYou can cast to plain IList and it works as expected. You can even use Add on it. https://dotnetfiddle.net/jcjchk https://dotnetfiddle.net/jcjchk
- lazulicurio 7y agoRight, but again, it means you're implementing two separate interfaces. You can implement IList without implementing IList<T>, and you can implement IList<T> without implementing IList.