Simple question. In Java 8, we have a huge number of new methods in the JDK classes. Let's say we created such a class using Java 7 (or Java 6):
class MyArrayList<E> extends ArrayList<E> {
public void sort(Comparator<E> c) {
}
}
This is a very reasonable implementation. Now we try to compile it with Java 8 and get the expected compilation error:
error: name clash: sort(Comparator<E#1>) in MyArrayList and sort(Comparator<? super E
public void sort(Comparator<E> c) {
^ where E
E
E
Here I would like to ask 2 questions:
Even with a parameter javac -source 1.7 -target 1.7using JDK 8, I get the same error - why? I thought that these options should allow compiling legacy code.
How about backward compatibility in general?
EDIT To be precise, maybe I'm doing something wrong? JDK 1.8.0_65, Mac OS X:
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
public void sort(Comparator<E> c) {
^
where E
E
E
1 error
1 warning