wood burning stoves *
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

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>();

Sla.add("Hello");
Sla.add("Test");
Dog = Sla;
Dog.add(null);

for (String d: Dog)
System.out.println(d);
}
}
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Error K&B book