4 ms·
The codebase I work with has base classes like Thing, then Thing<T> : Thing, with the parts that don't need the T going in Thing.
by jimmaswell 8y ago
The codebase I work with has base classes like Thing, then Thing<T> : Thing, with the parts that don't need the T going in Thing.
- lazulicurio 8y agoSure, 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 8y 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 8y 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.