最近,我读了这篇文章:http: //download.oracle.com/javase/tutorial/extra/generics/wildcards.html
我的问题是,而不是创建这样的方法:
public void drawAll(List<? extends Shape> shapes){
for (Shape s: shapes) {
s.draw(this);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以创建一个这样的方法,它工作正常:
public <T extends Shape> void drawAll(List<T> shapes){
for (Shape s: shapes) {
s.draw(this);
}
}
Run Code Online (Sandbox Code Playgroud)
我应该使用哪种方式?在这种情况下,通配符是否有用?