3 ms·
> Java has one of the least good generics implementations of modern languages. I suggest C# ... What are the particular differences that make you suggest C# ov
by thethirdone 8y ago
> Java has one of the least good generics implementations of modern languages. I suggest C# ...
What are the particular differences that make you suggest C# over Java generics? As far as I am aware they are nearly identical for practical use (as language constructs). Things like Java using type erasure don't actually affect the language much only the particular compiler implementations.
- int_19h 8y agoThey affect the language a lot in non-trivial applications. For example, you can't implement the same generic interface with different type parameters, even when it is perfectly meaningful: suppose we have an interface Convertible<T> that objects that can be converted to T should implement - why can't an object implement Convertible<int> and Convertible<string> at the same time? Ditto with overloads - suppose you have a family of functions like frob() that apply to ints and doubles - so there's frob(int) and there's frob(double). So far, so good. Now, you want to add helpers to do the same for collection - and so there's frob(Iterable<int>) and frob(Iterable<double>)... except that doesn't work, because you can't overload on a generic interface, since the method signature has that information erased entirely. And then, of course, it breaks Reflection. Which is not so common in application code, but has many valid uses in the libraries.