The following code:
import java.util.*;
public final class JavaTest {
public static <T extends Comparable<? super T>> int max(List<? extends T> list, int begin, int end) {
return 5;
}
public static void main(String[] args) {
List<scruby<Integer>> List = new ArrayList<>();
JavaTest.<scruby>max(List, 0, 0);
}
}
class scruby<T> implements Comparable<String>{
public int compareTo(String o) {
return 0;
}
}
How is the JavaTest.max (List, 0, 0) operator compiled? How scruby meets
T extends Comparable <? super T>
Comparable<String>Does it implement that is not a super-type of scruby? If you change it to scruby<Integer>, it will not compile and will throw an error. So why is it compiling now? Why is the source type compiled?
source
share