my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question of K&B book on Generic Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question of K&B book on Generic Collections" Watch "Question of K&B book on Generic Collections" New topic
Author

Question of K&B book on Generic Collections

L Yan
Greenhorn

Joined: Apr 25, 2006
Posts: 18
Hello,

Would somebody explain why option C is not correct? Thanks a lot.

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;
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Please have a look at the errata for this book. This question is listed there.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
L Yan
Greenhorn

Joined: Apr 25, 2006
Posts: 18
Yes. I saw it on error list. But it doesn't have the correction.

Also I compiled the code, it did fail me because:

Group.java:14: incompatible types
found : java.util.List<capture of ? super java.lang.Integer>
required: java.util.List<java.lang.Number>
output = process(input);
^
1 error

I don't know why java.lang.Number is not ? super java.lang.Integer.

Thanks.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

According to my copy of the book the answers are b e f after you change List<? super E> to List<E>. I have not looked into the errata but i think i remember someone acknowledging that change.
elPete Martin
Greenhorn

Joined: Apr 27, 2006
Posts: 5
Where can I find the errata for this book??
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

There is a link at the beginning of the SCJP forum page that points to the errata. Its grouped along with other important links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question of K&B book on Generic Collections
 
Similar Threads
please explain this!!
Generics Question
answer to this question
Question about generics
doubt abt Generics mock question - from K&B