wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K & B book question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K & B book question" Watch "K & B book question" New topic
Author

K & B book question

Bing Qiao
Greenhorn

Joined: Oct 24, 2006
Posts: 21
Page 634, a16

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

A programmer wants to use this method like this:



Which pairs of declarations could be used for successful compilation?

....
C. ....

Answer:
C is wrong because the return type evaluates to List<Integer>, and that can't be assigned to a variable of type List<Number>.
....


The book is obviously correct saying that C won't compile.
But I thought List<? super E> meant both E and E's supertypes could be returned. Why must the return type evaluate to List<Integer> then?

Many thanks!
[ October 26, 2006: Message edited by: Bing Qiao ]
Naveen Zed
Ranch Hand

Joined: Aug 11, 2006
Posts: 61
Hello,
This was in the erraa list of K&B.so the changed thing is
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I think this may be in the errata.
Venkat Sidh
Ranch Hand

Joined: Sep 30, 2006
Posts: 61
Naveed,

You mean C is also correct answer based on Errata.
Bing Qiao
Greenhorn

Joined: Oct 24, 2006
Posts: 21
Sorry, but this is not in the Errata.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
It is in this list.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K & B book question
 
Similar Threads
K & B Generics Quiz question.
wildcards in generics
Generics question problem
K&B Mock question on generics
Tough Generics question from S&B 5.0 book