You know, when I use Eclipse I get the feedback to "does this compile" type questions immediately. It gives me the message as I type since it compiles on the fly. Sometimes it even suggests remedies. I bet other IDE's do this too.
That way, you can narrow your problem down to a specific question without exhausting the good people on these boards.
There's no place like 127.0.0.1
Joined: Jun 07, 2007
Could you tell me why it is not able to compile..? why call 1 and call 4 are able to compile since there is super of class Object. and why call 2 is not compiling since every class extends object class.
This has the distinct look of a homework or interview question, so I shan't give a complete answer. However...
This type of code will compile if the declared type of the object reference is compatible with the type of object that you are trying to assign to it. In the case of generic collections, it is necessary that any object that could legally be added to the object you actually created (with "new") is also a legal member of the declared type of collection.
So, for instance, if the declared type was a List of String, but you actually created a List of Object, it would not compile, because it is legal to put things into a List of Object that would not be legal in a List of String.
Also, bear in mind that a List of Object is not a superclass of a List of String, even though Object is a superclass of String. This is the problem for which the "? extends A" and "? super B" syntax exists. A List of "? extends Object" IS a superclass of a List of String.
Lastly, can you (or anyone) think of any real use for "? super Object"? I can't!
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.