Search code examples
javajava-6java-5

How do I link a Java 1.5 class with a Java 1.6 class?


Using a Java 1.5 compiler, when I try to compile a java class that depends on a class that was compiled with Java 1.6, I get this error:

in/javac Java15.java
Java15.java:5: cannot access Java16
bad class file: ./Java16.class
class file has wrong version 50.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
        String java16result = Java16.test();
                              ^
1 error

The reverse works (Using a Java 1.6 compiler, I can link with a Java 1.5 class.)

Is there any sort of workaround for this?


Solution

  • The solution that worked for me was to use java.lang.Runtime.exec to execute a Java 1.6 program from a Java 1.5 program.

    I realize this is probably not the best solution in most cases, but in my case (where I needed to call a Java 1.6 program from an Oracle Database using Java 1.5), it worked fine, and didn't require any changes to my current database installation.