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()); // problem is here
}
}
compilateur
me donner un message d'erreur:
The method setData(List< User >) in the type Service is not applicable for the arguments (List< Object >)
et si je tente de lancer avec liste l'erreur:
Cannot cast from List< Object > to List< User >
result.setData(new ArrayList<User>());
fonctionne très bien mais je ne veux pas passer.
il fonctionne sur java 8 – ZhongYu