Forums.ATC.no

Teknisk => Generelt teknisk => Emne startet av: Floyd-ATC på 08. April 2015, 22:24 pm

Tittel: Java code compiled with JDK8/JRE8 crashes when executed in JRE7
Skrevet av: Floyd-ATC08. April 2015, 22:24 pm
One example of code that ran perfectly well in JRE7 when compiled using JRE7:

Kode: [Velg]
ConcurrentHashMap hash =  /* contents here... */
for (Integer key : concurrenthashmap.keySet()) {
    /* Do something with the key here */
}

However, when compiled with JRE8 this code would only run on JRE8, on JRE7 it would crash with
Kode: [Velg]
java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
Because Java, that's why.

There is no other way around this problem except to compile using JRE7. Here's how to do that with Eclipse:


Eclipse should now compile your Java code to be compatible with JRE7 and complain if you are trying to use features that only exist in JRE8 (or newer).
Tittel: Sv: Java code compiled with JDK8/JRE8 crashes when executed in JRE7
Skrevet av: Cybersyn24. April 2015, 09:43 am
If you install JRE 7 alongside JRE 8, you'll probably want to inspect the PATH environment variable to make sure JRE 7 doesn't steal the spotlight.