• 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

Generics Problem

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can anybody please explain this Question16 on Pg 634 from K&B book-
public static <E extends Number> List<? super E> process(List<E> nums)
Before answering the question I am not sure how to read the above line and interpret what is the return type and parameter passes etc.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by neha verma:
Hi,
Can anybody please explain this Question16 on Pg 634 from K&B book-
public static <E extends Number> List<? super E> process(List<E> nums)
Before answering the question I am not sure how to read the above line and interpret what is the return type and parameter passes etc.



Well, we can tell you what it is, but unless understand it -- at least to read it -- it may not help. I recommend that you reread the chapter.

Anyway, to answer your question... This defines a method (named process), which takes a List of E, called nums. The type of E is bounded, in that it must either be Number or one of it's subclasses. The method returns a List of objects, whose type is also bounded -- its type is either E or one of it's superclasses.

Henry
[ July 14, 2007: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neha,

Refer to K&B Errata before analysing answers given in book as there is a typo in question.

Murali...
 
Would you like to try a free sample? Today we are featuring tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic