This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes generics question 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 "generics question" Watch "generics question" New topic

generics question

adolfo bulfoni

Joined: Aug 13, 2008
Posts: 2
hi guys, I have some doubts on a question I took from one of the two practice tests (test a) of SCJP6 cd.

List<T> output = new LinkedList<T>();
for(T t: input)
return output;

and here are the 4 correct answers:

public static <T> List bw(List <T> input){
public static <T> List bw(List <? extends T> input){
public static <T> List<? extends T> bw (List <T> input){
public static <T> List<? super T> bw (List <T> input){

i dont understand why the 3rd and the 4th are correct answers.. the output list is a list of <T> so why is it accepted as return value a list of <? super T> or a list of <? extends T> ?
victor kamat
Ranch Hand

Joined: Jan 10, 2007
Posts: 247
<? extends T> says T or a subclass of T;
<? super T> says T or a parent of T.

In the first case T definitely is <? extends T> and so is correct.
In the second case T definitely is <? super T> and so is correct.
It is sorta covered in the JavaRanch Style Guide.
subject: generics question
Similar Threads
Solution needed for Generics Question
SCJP question from learnkey -- generics
Generics, K&B Mock, what's the answer?
K & B Mock exam Generics doubt