Capturing wildcards in Java generics

浪尽此生 提交于 2019-11-29 10:00:00

List<?> does mean list of object of unknown type, it's not the same as List<Object>.

Because we don't know the type of elements in the list result of i.get(0) is considered by Java as Object, and you cannot add Object to List<?>. In case as your Java could be smarter, but in more complex code with <?> wildcards it's easy to make it no type safe.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!