It’s always a good idea to have your development environment as close as possible to production. When working with Java first thing to consider is JDK version. It’s possible to use a newer version of JDK for development but it’s not a good idea. A couple of problems can arise if our development JDK version is different from target version.

Let’s say, for example, that we are working on a project that uses Java 5 in production but development is done using Java 6. Eclipse can set the code compliance on a project and that will set compiler target to defined version. But actual JDK libs against which our project is compiled still belong to JDK 1.6. So if we were to use String.isEmpty() that was added in Java 6 our compiler wouldn’t have a problem with that and error will be caught only when build is done using JDK 1.5.

Another possible problem is connected with addition of new method overloads.
For example:

public class A {

  /**
  * @since 1.5
  */
  public void example(Object o) {
  // do something
  }

  /**
  * @since 1.6
  */
  public void example(String s) {
  // do something completely different
  }
}

Class A in Java 5 has a method: public void example(Object o). In Java 6 new overload was added: public void example(String s).
If we do this:

public static void main(String[] args) {
  new A().example("test");
}

Eclipse will tell us we are using newer overload. Our compiler won’t have a problem with this. Even when we build this using JDK 1.5 no error will occur as compiler thinks we are using older overload. Problem is that this will not be caught in compile time. In runtime older overload will be used, a method we did not intend to use.
Severity of this depends on how different are these two overloads. Something like this can have unpredictable side effects and it’s possible for this bug to go unnoticed for a long time.

0 comments