This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

Generics

Katrin Perry
Ranch Hand

Joined: Mar 07, 2007
Posts: 60
Hi,

I came across a question in the Whizzlab test, whose answer I have found confusing.

According to it this code would compile but with warnings:

public static void main(String[] args) {

List<? extends Object> ll = new LinkedList<? extends Object>();
ll.add("String");
ll.add(4);
ll.add(true);
ll.toString();

}


but this one would compile without warnings:

public static void main(String[] args) {

List<Object> ll = new LinkedList<Object>();
ll.add("String");
ll.add(4);
ll.add(true);
ll.toString();

}


My understanding is that:

List<Object> ll = new LinkedList<Object>();
mean the same thing as

List<? extends Object> ll = new LinkedList<? extends Object>();
but not according to Whizzlab

Could anyone clarify please?

Thank you
Katrin


Katrin
SCJP 5.0, SCWCD, SCBCD
Katrin Perry
Ranch Hand

Joined: Mar 07, 2007
Posts: 60
Sorry, the second code extract would cause compile error according to Whizzlab.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

Note: You can use code tags to make the forum format your code nicely.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Katrin Perry
Ranch Hand

Joined: Mar 07, 2007
Posts: 60
Thanks for the suggestion, but this can't be a reason not to answer my question.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

Continued here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics
 
Similar Threads
mixing generic & nongeneric
Generics
Linked List need help
removal of elements in linkedlist of java
Adding null values into a LinkedList