[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[jdt-core-dev] Compiling against JDK8 but staying compatible with 1.7 bytecode
|
Hi,
I'm in the position that I have to compile against JDK8 (because of
libraries contained in there) but the .class file should still be
useable in Java7.
Now I tried put the following settings in a project which runs against
the BETA_JAVA8 branch.
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.source=1.8
As a test I've created a project which looks like this:
import java.util.AbstractList;
import java.util.Comparator;
public class Test extends AbstractList<String> {
private String[] internal = {"Hello","World"};
@Override
public void sort(Comparator<? super String> c) {
// TODO Auto-generated method stub
}
@Override
public String get(int index) {
return internal[index];
}
@Override
public int size() {
return internal.length;
}
}
import java.util.function.Consumer;
public class Bla {
public static void main(String[] args) {
System.err.println("HELLO WORLD");
Test t = new Test();
// t.forEach(new Consumer<String>() {
//
// @Override
// public void accept(String t) {
// System.err.println("Value: " + t);
// }
// });
for( String s : t ) {
System.err.println(s);
}
}
}
And the code runs fine in Java7 and Java8. My question now is does this
only work by chance, or is it possible to compile to 1.7 bytecode if no
1.8 features are used?
From https://bugs.eclipse.org/bugs/show_bug.cgi?id=390889 I somehow
have the feeling that this is not supposed to work at all.
Tom