File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.
I agree. Here's the link:
subject: generics question
It's not a secret anymore!