This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Error K&B book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic

Error K&B book

victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
K&B pg 610, fourth bullet states that the generic class List<? extends Dog> can be accessed but not modified.
The code shows that this incorrect.

import java.util.*;

public class Test
public static void main(String... args)
List<String> Sla = new ArrayList<String>();
List<? extends String> Dog = new ArrayList<String>();

Dog = Sla;

for (String d: Dog)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You may remember that you posted this before

Adding null is allowed but is rather pointless.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Don't get me started about those stupid light bulbs.
subject: Error K&B book
Similar Threads
K&B Error
How Does the Compiler Know Not To Allow Adding to a Generic List With a Wildcard?
Type of the Generic List
Generics adding to List (? extends Object)
Regarding Generics