I maintain 2 projects with the same functionality and I am consolidating this functionality into a commons project. I defined an interface:
public interface GraphData { public List<? extends ShapeData> getShapes(); public void setShapes( List<? extends ShapeData> shapes ); } I implement this interface in both projects:
public class Graph implements GraphData { public List<Shape> shapes = new ArrayList<Shape>(); public List<? extends ShapeData> getShapes() { return shapes; } public void setShapes( List<? extends ShapeData> shapes ) { this.shapes = shapes; } } Shape is a subtype of ShapeData. When I compile this class I get an error about casting List<Shape> to List<? of... How do I resolve this compilation error? Maybe a better question is, should I define my interface methods using the bounded wildcard (i.e. ? extends)?
List<? extends ShapeData>to aList<Shape>. It's difficult to know what to suggest without seeing some context.