• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

wildcards again....

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

In the boldened line in this code, doesn't <?> get substituted with <Apple> during compile time? (I was thinking it would...)

The compiler shows me an error for using the next statement...

Basket.java:18: setElement(capture of ?) in Basket<capture of ?> cannot be appli
ed to (Apple)
b5.setElement(new Apple());




 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No it doesn't get substituted with Apple.

b5 is a reference to a Basket that can contain anything.

The problem is that it could also refer to a Basket that contains a class that isn't an Apple or a superclass of Apple.

So you can't safely add an Apple to it.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey can anyone explain me why to use <? ...> while creating object.
 
reply
    Bookmark Topic Watch Topic
  • New Topic