• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Upper bounded wildcards

 
Ranch Hand
Posts: 34
2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm currently (trying) to study generics reading both Mala Gupta and K&B books.

In Mala Gupta printed book at pag 258:



and given a static method wrapGift() defined so that we restrict its type arguments to Gift or its subclasses



then in the exam tip box it says:


In the preceding method wrapGift(), the loop variable item can be of type Gift or its subtype, Object.



Is this an typo (I mean subtype - Object)?
Should it be supertype - Object?
Or should it be subtype Book and Phone?

Considering also what states the attached table (ref. pag 259 same book).

Thanks for your help.
Marco
Wildcards.PNG
[Thumbnail for Wildcards.PNG]
Wildcards
 
Author
Posts: 213
10
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Supertype Object.

The thing in the list is <? extends Gift> which means it's a Gift or some particular Gift (Book, etc.)

The variable types to which this may be assigned safely (that is, the loop variable) is Gift or a supertype of Gift (i.e. Object).

HTH
Simon
 
Attractive, successful people love this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic