You are correct. Multi-catch is a Java 7 language feature and there is no way to compile it to Java 6 (or earlier) JVM compatible bytecode.
Using a Java 7 compiler, the following allows you to compile Java 6 compatible bytecode:
javac -source 1.6 -target 1.6 MyJavaFile.java
When you attempt to compile a Java 7 language feature (multi-catch, for example) you will get:
roach$ javac -source 1.6 -target 1.6 test.java
warning: [options] bootstrap class path not set in conjunction with -source 1.6
test.java:9: error: multi-catch statement is not supported in -source 1.6
} catch (NullPointerException | BufferOverflowException ex) {}
^
(use -source 7 or higher to enable multi-catch statement)
1 error
1 warning
(For more about what that warning
means, see:
https://blogs.oracle.com/darcy/entry/bootclasspath_older_source - it's not relavent to this discussion)
If you change the -source
flag to 1.7
you will receive:
source release 1.7 requires target release 1.7
Because ... you can't compile Java 7 source (e.g. source that has Java 7 features) to Java 6 compatible bytecode.
If you compile it with Java 7 (with no -source
or -target
flag) you will get Java 7 bytecode which can not be run on a < Java 7 JVM. And if you try to do so you will receive an error telling you the versions don't match:
roach$ /Library/Java/Home/bin/java net.mostlyharmless.multicatch.App
Exception in thread "main" java.lang.UnsupportedClassVersionError:
net/mostlyharmless/multicatch/App : Unsupported major.minor version
51.0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…