A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Joined: Apr 07, 2007
Jul 05, 2007 01:10:00
Given a method declared as: public static <E extends Number> List<? super E> process(List<E> nums) A programmer wants to use this method like this: // INSERT DECLARATIONS HERE output = process(input); Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.) C. ArrayList<Integer> input = null; List<Number> output = null;
The explanation is given as from k&B:
C is wrong because the return type evaluates to List<Integer>, and that can't
be assigned to a variable of type List<Number>.
how do we evaluate the type to be <Integer> as explained by the book??
and how come the option C is wrong. (Note other option are removed.)
Joined: Feb 28, 2007
Jul 05, 2007 01:36:00
Did you see K&B errata:
Joined: Mar 22, 2007
Jul 05, 2007 05:09:00
Try the following:
ArrayList<Integer> input = null; List<? super Integer> output = null;
[ July 05, 2007: Message edited by: Sergio Tridente ]
SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: Generic doubts
About Chapter 7: Generics and Collections
wildcards in generics
A Generic Question. Thanks.
doubt abt Generics mock question - from K&B
K & B Generics Quiz question.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013