Hi, I have a question about Generics,like this public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("abc"); printName(list); } public static <T> void printName(List<T>list) { System.out.println(list.get(0).getClass().getSimpleName()); } public static <T> void printName2(List<T>list,Class<T>cls) { System.out.println(cls.getSimpleName()); }
If the list is empty,the method "printName" is in error. exclude this two methods,is any other way to get the Type of the elements of List? Thanks for your help. -- You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en