• 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

Question on generics

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pg no 634 on K&B book

public static <E extends Number> List<? super E> process<List<E> nums>

now the method to be used is
//declaration
output=process(input);

which declaration could be placed?

a)ArrayList<Integer> input=null;
ArrayList<Integer> output=null;
b)ArrayList<Integer> input=null;
List<Integer> output=null;
c)ArrayList<Integer> input=null;
List<Number> output=null;
d)List<Number> input=null;
ArrayList<Integer> output=null;
e)List<Number> input=null;
List<Number> output=null;
f)List<Integer> input=null;
List<Integer> output=null;

the ans is b,e anf f.Pls explain
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am not sure... the only declaration i think that will compile is

List<? extends E> output = null;

where E is whatever you choose to define input...
 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Recently the book's authors released an Errata where the original question has been changed to :

public static <E extends Number> List<E> process(List<E> nums)

You can see here a complete list of all erros discovered till now.
 
This tiny ad is guaranteed to be gluten free.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic