• 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

wildcards doubt again

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In generics using wildcards,
cannt we have ? on the RHS of Collection -declaration & initialization experession.
ie.
List<?> mylist=new ArrayList<? extends Object>();
Why is this so?
--From K&B ,chap7 pg 596

Thank you
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the first part you declare a reference type and with the wild card you say the reference could be <? extends ...> Every object that extends from the given object type.

In the second part you create an object. This object should be of a certain class and could not defined as we don't know what kind of object it is but it could extend a given objecttype. No it is just a object of type X.

So you cannot use wild card notation in the object creation only as a reference.
 
reply
    Bookmark Topic Watch Topic
  • New Topic