姬長信(Redy)

java – 通过使用泛型’extends’添加字符串…


代码如下:
List extends String> genericNames = new ArrayList();
genericNames.add("John");

给编译器错误:

Multiple markers at this line
– The method add(capture#1-of ? extends String) in the type List is not applicable for the
arguments (String)
– The method add(capture#1-of ?) in the type List is not applicable for the arguments (String)

导致此错误的原因是什么?我是否应该无法添加字符串或其子类型,因为我在类型参数中扩展String?