Supun Lakshan Dissanayake wrote:
Rob Spoor wrote:<? extends Object> is practically the same as <?>.
Thanks Rob!
But I mean this,
Consider this
if we can't add an integer to arraylist what's the purpose of it?
Thanks
in your example, arrayList is an array list of some type X, where X could be sub-type of Number
i.e. it could be array list of Number, Integer, Double, etc.
In the case of Double, it could not hold Integer. So, you got compile time error.
According to PECS (Producer Extends, Consumer Super), if your collection is going to consume some value, it should use
super instead of
extends.
which may be