? extends Object
您正在使用通用通配符。您不能执行添加操作,因为类类型不确定。您不能添加/放置任何东西(null除外)。
有关使用通配符的更多详细信息,请参考oracle
docs。
Collection<?> c = new ArrayList<String>();c.add(new Object()); // Compile time error
由于我们不知道c的元素类型代表什么,因此无法向其添加对象。该
add()方法采用参数
typeE,即集合的元素类型。当实际类型参数为时
?,它代表一些
unknowntype。我们传递来添加的任何参数都必须是该未知类型的子类型。由于我们不知道那是什么类型,因此我们无法传递任何内容
The sole exceptionis null, which is a member of every type。



