Generics: difference between a wildcard vs Object

The short version is:

Collection<Object> != (Collection<?, ?> == Collection)
or
Map<Object, Object> != (Map<?, ?> == Map)
Why? Using just Collection is — since Java 5 & the introduction of Generics — a short form for Collection<?> collectionOfUnknown which is not the same as Collection<Object> collectionOfObjects because you can assign any collection to collectionOfUnknown like Collection<Foo> collectionOfFoos, Collection<Bar> collectionOfBars or Collection<Object> collectionOfObjects but you cannot assign Collection<Foo> collectionOfFoos to a Collection<Object> collectionOfObjects.

Comments

Popular posts from this blog

Tuning ext4 for performance with emphasis on SSD usage

NetBeans 6.1: Working with Google´s Android SDK, Groovy and Grails