my case is : a save method in ResourceService<T , ID >
public interface IResourceService<T,ID>
public class ResourceService<T , ID> implement IResourceService<T,ID>
{
public void save(T entity) throws RuntimeException {
try {
AsyncServiceSaveRunable<T> task = new
AsyncServiceSaveRunable<T>(getService(),entity);
this.treadPoolExcutor.submitTask(task);
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and in
public class AsyncServiceSaveRunable<T> implements Runnable {
private IResourceService<?,?> service; //----> this is
private Method serviceMethod;
private List<T> parameters;
public AsyncServiceSaveRunable(IResourceService<?,?> service, List<T> parameters){
}
public AsyncServiceSaveRunable(IResourceService<?,?> service, T parameter)
throws NoSuchMethodException, SecurityException{
this.service = service;
this.parameters = new ArrayList<T>();
this.parameters.add(parameter);
}
@Override
public void run() {
try {
if(this.parameters.size()>1)
service.saveList(this.parameters);
else
service.save( this.parameters.get(0));
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
the problem is service.saveList(this.parameters); and service.save(…);
are wrong
is there anyway to pass that parameter
or i need a different of structure to deal this kind of case?
Thanks
——————error message from eclipse ————————
The method save(capture#7-of ?) in the type IResourceService<capture#7-of ?,capture#8-of ?>
is not applicable for the arguments (T)
In
ResourceService<T extends BaseEntity, ...>you requireTto be drevied fromBaseEntity.In
public class AsyncServiceSaveRunable<T>Thas no restrictions.Then in
service.save(this.parameters.get(0));you try to pass the (unbounded) generics type to a function that requires aBaseEntityobject (or one derived from it).You can require the type parameter of
AsyncServiceSaveRunableto be derived from BaseEntity as well:UPDATE:
The error message is that the first type parameter of
IResourceServiceis not valid for the type required bysave(). Previously you had the type parameter bounded byBaseEntry, but this restriction is now missing. Maybe you want to write:IResourceService<? extends BaseEntity, ? extends Serializable>?