简单的问题。在Java 8中,JDK类中有大量的新方法。假设我们使用Java 7(或Java 6)创建了这样的类:
class MyArrayList<E> extends ArrayList<E> {
public void sort(Comparator<E> c) {
// some sort
}
}这是相当合理的实施。现在,我们尝试用Java 8编译它,并接收可预期的编译错误:
error: name clash: sort(Comparator<E#1>) in MyArrayList and sort(Comparator<? super E#2>) in ArrayList have the same erasure, yet neither overrides the other
public void sort(Comparator<E> c) {
^ where E#1,E#2 are type-variables:
E#1 extends Object declared in class I.MyArrayList
E#2 extends Object declared in class ArrayList在此,我想提出两个问题:
javac -source 1.7 -target 1.7选项,我也会收到相同的错误--为什么?我认为这些选项应该允许编译遗留代码。编辑准确地说,可能是我做错什么了吗?JDK 1.8.0_65,Mac:
bash-3.2$ javac -version
javac 1.8.0_65
bash-3.2$ javac -source 1.7 -target 1.7 MyArrayList.java
warning: [options] bootstrap class path not set in conjunction with -source 1.7
MyArrayList.java:7: error: name clash: sort(Comparator<E#1>) in MyArrayList and sort(Comparator<? super E#2>) in ArrayList have the same erasure, yet neither overrides the other
public void sort(Comparator<E> c) {
^
where E#1,E#2 are type-variables:
E#1 extends Object declared in class MyArrayList
E#2 extends Object declared in class ArrayList
1 error
1 warning发布于 2016-01-12 22:47:04
-bootclasspath选项)才能交叉编译。https://stackoverflow.com/questions/34755121
复制相似问题