O. Ziggy wrote:
I dont understand the instance creation type. What is the significance of it being a String instance? Does it make any difference? ( i tried adding a string object to the collection and the compiler didnt like it)
Quite frankly. Don't do this.
It makes no sense to create a collection of a particular type, and then tell the compiler to forget about the type -- on the same line.
Wildcards are more commonly used for parameters, where you want to write a method that can work with multiple collection types. And where you don't care about the type.... for example, a method that iterates through the collection, and prints out the output from the toString() method. Without wildcards, you would probably have to disable generics altogether to write a generic printing method.
Henry