I read a tweet today that said:
It\'s funny when Java users complain about type erasure, which is the only thing Java got right, while ignoring all th
This is not a direct answer (OP asked "what are the benefits", I am replying "what are the cons")
Compared to C# type system, Java type erasure is a real pain for two raesons
In C# you can implement both IEnumerable and IEnumerable safely, especially if the two types do not share a common ancestor (i.e. their ancestor is Object).
Practical example: in Spring Framework, you can't implement ApplicationListener extends ApplicationEvent> multiple times. If you need different behaviours based on T you need to test instanceof
(and you need a reference to Class to do that)
As others commented, doing the equivalent of new T() can only be done via reflection, only by invoking an instance of Class, making sure about the parameters required by the constructor. C# allows you to do new T() only if you constrain T to parameterless constructor. If T does not respect that constraint, a compile error is raised.
In Java, you will often be forced to write methods that look like the following
public T create(....params, Class classOfT)
{
... whatever you do
... you will end up
T = classOfT.newInstance();
... or more advanced reflection
Constructor parameterizedConstructorThatYouKnowAbout = classOfT.getConstructor(...,...);
}
The drawbacks in the above code are:
ReflectiveOperationException is thrown at runtimeIf I was the author of C#, I would have introduced the ability to specify one or more constructor constraints that are easy to verify at compile time (so I can require for example a constructor with string,string params). But the last one is speculation