I\'m experimenting with generics in Java, and thought of this example.
If I have ClassA, I can override it with a subclass that references a co
Thanks to type erasure, this:
public void doSomething(T data);
Really means this:
public void doSomething(Object data);
So no, there isn't a way to override with a more restrictive parameter type.
Also in this code:
class ClassA {
public void doSomething(T data) {};
}
The type parameter in your class name and the type parameter in the method are actually different parameters. It's like declaring a local variable of the same name as a variable in a higher scope. You can call doSomething(123) on an instance of ClassA because the second T is local to the method.