• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 23928
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...
 
Seriously Rick? Seriously? You might as well just read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic