I am really having a tough time understanding the wild card parameter. I have a few questions regarding that.
? as a type parameter can only
Lower-bound says: You can use the class mentioned after 'super' keyword, or any of its super types. This can get tricky. Those super types may have other (completely different) classes inheriting from them, as below example shows.
Say,
List super Car> cars = new ArrayList ();
Should the programmer be allowed to write:
cars.add(new Helicopter()); //Helicopter is a kind of Vehicle
That should obviously not be allowed, and it reflects a danger in using lower-bounds.
Programmer should be allowed to add a Vehicle to list, but not ANY Vehicle. He must cast it, to let Java know he is only adding a Car Vehicle after all, like this:
cars.add((Car) new Vehicle());