Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

Error K&B book

 
victor kamat
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
You may remember that you posted this before

Adding null is allowed but is rather pointless.
 
    Bookmark Topic Watch Topic
  • New Topic