regarding String your understanding is correct, we can add only String object as it can not be extended [ September 09, 2008: Message edited by: ramesh maredu ]
SCJP 1.5 94%.
The greatest glory in living lies not in never falling, but in rising every time we fall.
<? super Object> means you can have Object type or its Super Class type at type where you are mentioning the type.It means whatever the Type you are mentioning in Generic it should be Object or its Super Object T should be Super of Object mens Super Classtype not SubClass type.But this method will allow you to add thngs to The collection that type.But The method with following Declaration gives compilation error when you try to add the Objects.<? extends Object>.It menas the type can be either Object or its SubClass.Just remeber its Declaration for type only.
When you gave decleration as <? super Object> you need to specify the type in method call.When you specify the the type then you can add only those type objects or the Objects which satisfy IS-A.
I think this will answer your Question.
Please correct me if i am wrong.
with Regards,<br />VidyaVikas Yalamanchili SCJP 5.0
Then, How about <? super String>, does it have same meaning? or means you can add String(String has no subClass), am I right with this point?
for <? super String>; you can add only String. because String final class and cannot have subclass. [ September 09, 2008: Message edited by: Vierda Mila ]
When you gave decleration as <? super Object> you need to specify the type in method call.When you specify the the type then you can add only those type objects or the Objects which satisfy IS-A.
so for example:
So this is conclusion! Thanks for help [ September 09, 2008: Message edited by: Doraemon Zhou ]
Preparing SCJP 6, try to get high score, and looking for a job...
The way that I like to look at this ( <? super ClassName> ) is like this
if you declare a reference...
List<? super ClassName> list1;
Then that reference can hold a List of ClassName or a List of anything higher in ClassName's class hierarchy.
THAT guarantees that whatever List you assign to list1... it WILL be able to accept a ClassName element.
If list1 will accept a ClassName type, then it will accept a subclass of ClassName type element.
Thus, a List<? super Number> reference will hold a Number, an Integer, a Float, a Double, or any other of the wrapper classes.
---------
Now, if you have a reference typed
List<? extends Number> list2;
then list two will be able to accept a List of Number or anything that is a subclass of Number. That means it will accept List<Number>, List<Integer>, List<Float> or any List of any other wrapper class. With that being true at run-time, the JVM can not be sure what type is currently referenced. All of the "type" information will have been wiped (type erasure). So the compiler, in order to guarantee the type safety of the List, simply will not allow anything to be put on that list using that reference. At run-time, yes, list2 COULD be a reference to List<Number>... but it COULD be a List<Float>. This rule keeps us from adding a short to the List<Float>.
------------------------
Bob
SCJP - 86% - June 11, 2009
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?