File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Error K&B book