Saturday 14 July 2012

The Art of Backporting: Using Java 5 features in Java 1.4

Backporting is the application of a patch or fix to a version of an application software which precedes that for which the patch was designed. One example would be the use of Java 1.5 features in Java 1.4. Basically your 1.5 code is used to generate bytecode that is compatible with a 1.4 VM.

Take for example generics which allows us to define objects with types as parameters, such as  List of Strings. Due to Java's implementation of generics using type erasure - whereby type information is in fact wiped out in the compilation phase - it is fairly easy to generate Java 1.4 compatible bytecode from 1.5 generics-based code. Victory to backporting!