• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

It can add element in the method that declare in wildcard generic fashion.

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, don't take it too hard. I just post it for fun (but it is correct thing except that it can't be consider the useful one). This is the code:

assume that the Animal and its subclass is correct implements.


This code is work fine, which mean it 'fine' both in compile and run time. I can invoking addAnimal( List<Dog> ) , addAnimal( List<Cat> ) as it was in wildcard generics fashion.

The point is, the method that declare wild cards generic (e.g. List<? extends SuperClass> can't invoking the 'modify' method such as add() of List. But you can add 'null' in this method and this 'null' will distribute to every List that you add to this method.

Best Regards
Tanakorn
[ February 11, 2007: Message edited by: Tanakorn Numrubporn ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hasn't this already been discussed quite recently?
 
Tanakorn Numrubporn
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry! for that.
I miss that posted.
 
Danger, 10,000 volts, very electic .... tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic