• 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

method types in Generics

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Based on JavaBeat.net question


Its giving compiler error at Line 2 indicating Basket<? super A> can't capture Apple;

If at Line 1 we change parameter "Apple a" to "A a" , it compiles and runs.

But A is also a Apple.

Can anyone give the scenario where "Apple a" will lead to runtime error if allowed.
[ June 14, 2006: Message edited by: S Thiyanesh ]
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basket< ? super A > b can only add an element of type A or sub-type.
so you can add an element of A or an element of sub type of A, not a super type of A.

'a' is an Apple which is a super type of A, so you can't add it.

That's my understanding. Someone can point it out if i am wrong.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic