This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Doubt in Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Doubt in Generics

Jisha Anand
Ranch Hand

Joined: Apr 02, 2009
Posts: 62

Dear All,

The following is a question from K & B SCJP5.0 guide:

Given a method declared as:

A programmer wants to use this method like this:


Which pair of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)

A. ArrayList<Integer> input = null;
ArrayList<Integer> output = null;

B. ArrayList<Integer> input = null;
List<Integer> output = null;

C. ArrayList<Integer> input = null;
List<Number> output = null;

D. List<Number> input = null;
ArrayList<Integer> output = null;

E. List<Number> input = null;
List<Number> output = null;

F. List<Integer> input = null;
List<Integer> output = null;

G. None of the above.

Correct Answers given are: B, E, F

But I thought the answer would be 'G' because the method returns a List<? super E> where E is the element type of the List which was passed as argument to the method 'process' & hence if:
'input' is List<Integer> then 'output' should be a List<? super Integer>.
Someone please help me with this question I think I got confused somewhere; but dont understand where

I have actually posted the same under forum subtopic 'Java Certification', but i got confused over the replies I got; hence posting it again, sorry for the trouble.

Thanks in advance!


SCJP, SCWCD, SCBCD
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39577
    
  27
Please do not post the same question to multiple forums: CarefullyChooseOneForum

Let's continue the discussion in the original thread. If you have questions about some of the answers, post them there for clarification.


Ping & DNS - updated with new look and Ping home screen widget
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt in Generics
 
Similar Threads
Explanation required for this answer
Generics Question
I have doubt in a question in Generics(Q16) SCJP5 K&B book
Doubt on a K & B SCJP5 guide question: GENERICS
SCJP 5 K&B question problem