I have a class Executorthat calls interface instances IService<T>with an argument KeyList<T>.
class Executor{
KeyList<?> _keys;
IService<?> _service;
public Executor(IService<?> service, KeyList<?> keys){
_service = service;
_keys = keys;
}
public void execute(){
_service.invoke(_keys);
}
}
interface IService<T>{
public void invoke( KeyList<T> keys);
}
class KeyList<T> {
List<T> _list;
}
I used <?>Executor for members, since it doesn't matter how IService and KeyList are parameterized, but the following causes a compilation error in which the arguments are not applicable:
public void execute(){
_service.invoke(_keys);
}
I suppose he complains because he is KeyList<?>not equal KeyList<T>, but <?>coincides with <? extends Object>, so I am a little confused. Is there a better alternative?
source
share