Un peu de polymorphisme dans ce monde de brutes
Bonjour, j'ai un soucis de polymorphisme. Ci-dessous un exemple simplifié de ma situation.
Code:
1 2 3
| public interface I {
Integer getValue();
} |
Code:
1 2 3 4 5 6 7 8 9
| public class A implements I {
public Integer getValue() {/*[...]*/}
public static void f(List<I> l) {
// [...]
for (ListIterator<I> it = l.listIterator(); it.hasNext();)
if (!it.next().getValue() > 1)
it.remove();
}
} |
Code:
1 2 3
| public class B implements I {
public Integer getValue() {/*[...]*/}
} |
Et dans mon main :
Citation:
method f in A cannot be applied to given types
required: java.util.List<I>
found: java.util.List<A>
C'est fâcheux ! Quelqu'un aurait-il une solution ? Merci de votre aide.