• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K & B book question

 
Bing Qiao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
This was in the erraa list of K&B.so the changed thing is
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this may be in the errata.
 
Venkat Sidh
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naveed,

You mean C is also correct answer based on Errata.
 
Bing Qiao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, but this is not in the Errata.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is in this list.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic