(I just want to clarify. I din't write the above. Maybe the OP has
something more to add.)
I haven't run into a situation in which erasure actually constrained the
compile-time programming model in any practical sense. Instead of
generic arrays you have generic collections.
It is mostly a performance issue. Autoboxed primitives are also slower
(and require more memory.)
We do have generic
methods, though for the example you suggest they're not needed.
No, not anymore, but see below.
The
following is perfectly legal in Java 1.5, and works with String,
StringBuffer, and many other classes, and doesn't require generics:
public static char charAt(java.lang.CharSequence s, int index) {
return s.charAt(index);
}
But this is not equivalent to my method. That only works on
CharSequences (which wasn't introduced until 1.4), my example works on
any class that has a char charAt(int) method. As it is now, we have to
wait until you guys decide that String or StringBuffer (or any other
classes for that matter) should implement this or that interface until
we can use them generically.
And just creating more and more interfaces to deal with this is not
really an alternative, as it is often redundant, and it requires
changing old code, which sometimes cannot be done.
I still don't see the point of your concerns.
Besides the above, java generics also lack many of the aspects of C++
template metaprogramming, like (partial) template specialization and
constant value templates. C++ templates are actually Turing complete.
But this is not something I miss, really.
But how about templates as template arguments:
template <template<class> class T, typename T2>
class SomeClass
{
T<T2> templateOfTemplateMember;
};
This can be useful at times. But as I said, I quite like the generics,
but that doesn't mean they are perfect.