有没有方法将具体类型列表转换为Java接口列表的接口?在Java中将具体类型列表转换为其接口列表
例如:
public class Square implements Shape { ... }
public SquareRepository implements Repository {
private List<Square> squares;
@Override
public List<Shape> getShapes() {
return squares; // how can I return this list of shapes properly cast?
}
}
由于提前,
上限
“*不能写入*”是不是*完全*精确:您仍然可以添加'null'并移除元素。 –
谢谢。更新以反映这一点。 – dlev
如果“那”在我的情况下很重要? – osrl