This discussion is archived
5 Replies Latest reply: Jul 3, 2013 5:31 PM by La VloZ RSS

Generics Question

La VloZ Newbie
Currently Being Moderated

Hello all

How are you all??

 

I have a little question for generics

see these two examples

 

public static void printList(List<?> list){
     for(Object elem : list){
          System.out.println(elem);
     }
}

 

and

 

public static <T extends Object>void printList(List<T> list){
     for(T elem : list){
          System.out.println(elem);
     }
}

 

they do the same thing i tried them

i know that the first is non-generic method and the second is generic method (if i'm not wrong)

but can someone tell me what's the diffrence between them which is the best practice and why??

 

Thank you all

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points