Bonjour,
Un correspondant me signale rencontrer le problème suivant avec mon code :
La ligne de code qui pose problème est la suivante :Error: (85, 136) java: incompatible types: java.util.List<capture#1 of ? extends jamel.util.Agent> cannot be converted to java.util.List<jamel.models.util.Employer>
Et voilà la déclaration de selectAll() :
Code : Sélectionner tout - Visualiser dans une fenêtre à part final List<Employer> newList = (List<Employer>) this.getSimulation().getSector(sectorName).selectAll();
La difficulté semble venir du fait que Agent et Employer sont deux interfaces indépendantes.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 /** * Returns a list of all agents of this sector, in a random order. * * @return a list of all agents of this sector. */ List<? extends Agent> selectAll();
Pourtant, lorsque la liste renvoyée par selectAll() contient des objets qui étendent à la fois Agent et Employer, je n'ai aucun problème.
Pourquoi mon correspondant rencontre-t-il, lui, dans les mêmes circonstances, ce problème ?
Comment résoudre cette incompatibilité ?
Partager