• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Super bounded WildCards -Doubt

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me explaining why this snippet would give ,capture-of error.
when i call this method.
This is exapmly frm K&B ,chap7pg 590.

With super-bounded ,we can pass generic type or super type but still erorr is coming.

void checkAnimals(List<? super Animal> animals) //Animal +subtype +no modification promise
{

animals.add(new Dog());

for(Animal a :animals ) //------animals give error
{
if(a!=null)
a.checkUp();
}
}
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lucky,

since we could do the following:Do you see the problem?
reply
    Bookmark Topic Watch Topic
  • New Topic