Here is my code. The compiler refuses to compile it :
private transient List<? extends Map<String, Object>> donnees;
// ...
public <M extends Map<String, Object>> void addDonnee(M nouvelleDonnee) {
getDonnees().add(nouvelleDonnee);
}
public List<? extends Map<String, Object>> getDonnees() {
// ...
return donnees;
}
Why do I get this error ?
The method add(capture#4-of ? extends Map<String,Object>) in the type List<capture#4-of ? extends Map<String,Object>> is not applicable for the arguments (M)
EDIT Here how I solve my problem :
private transient List<Map<String, Object>> donnees;
// ...
public void addDonnee(Map<String, Object> nouvelleDonnee) {
getDonnees().add(nouvelleDonnee);
}
public List<Map<String, Object>> getDonnees() {
// ...
return donnees;
}
And now the compiler is happy ! :)