aspose file tools*
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
Author

generics question

adolfo bulfoni
Greenhorn

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.

//INSERT CODE HERE
List<T> output = new LinkedList<T>();
for(T t: input)
output.add(0,t);
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.
 
jQuery in Action, 2nd edition
 
subject: generics question