I would like to have a method in an interface that accepts any Type of a generic object, like
public void myMethod(List<?>);
Now the implementations should only accept a certain type, eg. implementations 1:
public void myMethod(List<Integer>);
Implementation 2:
public void myMethod(List<String>);
However this does not work as public void myMethod(List<Integer>); is not a valid implementaion of public void myMethod(List<?>);
How could I achieve this? (Besides using an Object Parameter and hence rely on casting and do type checking manually)
Unless I’m missing something obvious (which happens too much for my liking), why not make the interface itself generic?
Which can be implemented like so:
and used like so: