Implémentation d'interface et génériques
Bonjour,
J'ai deux interfaces à implémenter. Je suis en 1.6 et bien entendu ces interfaces ne sont pas modifiables. Les voici :
Graph<P>
Code:
1 2 3 4
| public interface Graph<P> {
public P[][] getPoints();
public P getPoint(int x, int y);
} |
et
Point
Code:
1 2 3 4
| public interface Point {
public int getX();
public int getY();
} |
J'ai créé une implémentation de Point, PointImpl :
PointImpl
Code:
1 2 3 4 5 6
| public class PointImpl implements Point {
private int x; private int y;
public PointImpl(int x, int y) { this.x = x ; this.y = y}
public int getX() { return x;}
public int getY() { return y;}
} |
Jusqu'ici aucun problème... parcontre j'en recontre dans l'implémentation de Graph, GraphGrid :
GraphGrid
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class GraphGrid<P extends Point> implements Graph<P> {
private final PointImpl[][] points;
public GraphGrid(int width) {
points = new PointImpl[width][width];
for(int i = 0 ; i < width; i++) {
for(int j = 0 ; j < width; j++) points[i][j] = new PointImpl(i,j);
}
}
public P[][] getPoints() { return points; }
public P getPoint(int x, int y) { return points[x][y]; }
} |
Je suis obligé de respecter les signatures des méthodes de l'interface graph... (getPoints et getPoint) mais le compilo me sort :
cannot convert from PointImpl[][] to P[][]......
Que dois-je donc réellement faire pour implémenter cette interface?
Merci d'avance de votre aide !