Why does test1 cause an error while test2 does not? According to test2, <T extends Comparable<T>>
. But Manager implements Comparable<Employee>
, not Comparable<Manager>
, so why doesn't test2 cause an error?
public class Employee implements Comparable<Employee>{...}
public class Manager extends Employee{...}
public static <T extends Comparable<T>> void test1(List<T> t){ }
public static <T extends Comparable<T>> void test2(T t){ }
--------------------
List<Manager> listManager = new ArrayList<>();
test1(listManager); //ERROR
test2(new Manager());
Error message:
Required type:List<T>
Provided:List<Manager>
reason: Incompatible equality constraint: Employee and Manager
Any suggestion would be appreciated. Thank you.