5 Replies Latest reply: Jul 3, 2013 7:31 PM by La VloZ RSS

    Generics Question

    La VloZ

      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