Re: MapTool - Development - Java 6 vs Java 7 coding
Posted: Sat Sep 14, 2013 3:34 pm
Well. I don't have time to check this, but it used to work this way with Java 1.5 and 1.4, so I wonder why it should change with 6 and 7:
if you can get the compiler (j6 or j7) to create j6 code, it will run a priori on a jvm6. If you make use of classes that are available only in jre7 (or libs that are only delivered in j7 versions) than you will get "funny" errors during runtime. If you can't compile your code to j6, than extract the j7 code into a separate project, which you compile j7 style. Call an inconspicuous method in the other project so it can still compile to j6. (That method may use j7 behind the scenes.) After that you can package all classes into one jar.
If eclipse won't let you compile J6 in j6, then implement dubious() as empty in that compiler run, keep the classes and then make a j7 compiler run with J7 and implemented dubious(). Then combine the classes in one jar (or classpath). I'd be very suprised if that wouldn't run in a jvm6. (An important thing to keep in mind is that you need to avoid class constructors of j7 classes. They are sometimes called in unexpected places.)
if you can get the compiler (j6 or j7) to create j6 code, it will run a priori on a jvm6. If you make use of classes that are available only in jre7 (or libs that are only delivered in j7 versions) than you will get "funny" errors during runtime. If you can't compile your code to j6, than extract the j7 code into a separate project, which you compile j7 style. Call an inconspicuous method in the other project so it can still compile to j6. (That method may use j7 behind the scenes.) After that you can package all classes into one jar.
Code: Select all
class J6 {
static public void main(String[] argv) {
if (version > 1.6) J7.inconspicuous();
}
}
// -- different project
class J7 {
public static void inconspicuous() {
dubious();
}
private static void dubious() {
// fancy J7 code
}
}
If eclipse won't let you compile J6 in j6, then implement dubious() as empty in that compiler run, keep the classes and then make a j7 compiler run with J7 and implemented dubious(). Then combine the classes in one jar (or classpath). I'd be very suprised if that wouldn't run in a jvm6. (An important thing to keep in mind is that you need to avoid class constructors of j7 classes. They are sometimes called in unexpected places.)