Comparable VS <? extends Comparable>
问题 regarding the following code: public class Test <T extends Comparable>{ public static void main(String[] args){ List<String> lst = Array.asList("abc","def"); System.out.println(func(lst)); } public static boolean func(List<**here**> lst){ return lst.get(0).compareTo(lst.get(1)) == 0; } } why writing " ? extends Comparable" here would compile , and writing "Comparable" would not compile? thanks in advance. 回答1: This happens because generics are invariant . Even if String is a Comparable ,