class User{
private int id;
private String name;
public User(int id, String name) {
this.id = id;
this.name = name;
}
}
class Service<T> {
private List<T> data;
public void setData(List<T> data) {
this.data = data;
}
}
public class ServiceTest {
public static void main(String[] args) {
Service<User> result=new Service<User>();
result.setData(Collections.emptyList());
}
}
How to pass an empty list with a type parameter?
the compiler gives me an error message:
The setData (List <User>) method in the Service type is not applicable for arguments (List <Object>)
and if I try to use the List, then the error:
Cannot be dropped from <Object> to List <User>
result.setData(new ArrayList<User>()); It works fine, but I do not want to transmit it.
source
share