Bookmark Topic Watch Topic
  • New Topic

Error K&B book

 
victor kamat
Ranch Hand
Posts: 247
  • 0
  • 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
  • 0
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic