• 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

K&B "SCJP 5.0" Chapter 7 -Q16 - Error?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I just took the selftest and while reviweing the answers, I got stuck on the last question.

Q16:
Given a method declared as
-> public static <E extends Number> List<E> process(List<E> nums)
A programmer wants to use this method like this:
//INSERT DECLARATIONS HERE
output = process(input)

Which pairs could be inserted at //INSERT DECLARATIONS HERE ?

A.
B.
ArrayList<Integer> input = null;
List<Integer> output = null;
C.
ArrayList<Integer> input = null;
List<Number> output = null;
D.
E.
List<Number> input = null;
List<Number> output = null;
F.
List<Integer> input = null;
List<Integer> output = null;
G.

The answers should be B,E,F, but not C.

The explanation to C is:
"C is wrong because the return type evaluates to List<Integer>, and that can't be assigned to a variable of type List<Number>."
I absolutely understand this, but then, why is F correct?

Any help appreciated.

Many Thanks in advance.
 
Tommaso Nuccio
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oha!

I think I understand it now.
It's because in C the input is ArrayList<Integer>!!

Darn..

Thanks anyway.
 
reply
    Bookmark Topic Watch Topic
  • New Topic