Why java 1.4 compiler does not complain about a third party library compiled with 1.5 compiler ? The problem is encountered at runtime UnsupportedClassVersionError .
views:
34answers:
1why java 1.4 compiler does not complain about a third party library compiled with 1.5 compiler ?
As of Java 1.5, the class file format was changed slightly (to retain annotations, for instance). See the -target
option in the compiler docs. Java 1.5 and later JVMs support both class file formats; Java 1.4 VMs (naturally) only support the earlier format.
As for why the compiler doesn't complain: The compiler need only concern itself with whether it has enough information to correctly compile the files that it's been asked to compile; not whether it can run them correctly. The JVM needs to worry about running the classes correctly. Apparently, if you're seeing the 1.4 compiler happily referencing 1.5 classes from within the code it's compiling, the format change didn't affect the information the compiler needed to compile 1.4-style code. I can't immediately find a reference guaranteeing that behavior, but if it's what you're seeing...