Ok i just tested it it really goes wrong (in eclipse and with javac)
i have this test:
public class Main
{
public static void main(String[] args)
{
StringBuffer sb1 = new StringBuffer("sb1");
StringBuffer sb2 = new StringBuffer("sb2");
sb1.append(sb2);
System.err.println(sb1);
}
}
i compile this against 1.3 then the sb1.append(sb2) will invoke the
append(Object)
so also when executing on 1.4!
when i compile this against 1.4 (with now other settings )then
append(StringBuffer)
will be executed and executing it on 1.3 will not work (AbstractMethodError
or MethodNotFound)
When i compile it against the rt.jar of 1.4 but i set eclipse that i has to
see this as 1.3 code and target is 1.3
then still the wrong byte codes are generated also if say the samething to
javac then also the wrong byte
codes are generated. Still the append(StringBuffer) is invoked. so it still
doesn't run on 1.3 so even if target and source are 1.3
So the safest thing to do is really compile against the right rt.jar. The
rest just doesn't work
I tested this with 1.3 and 1.4 because this is the quickest test i did
know... But i don't think it will matter much with 1.4->1.5
johan
On 2/5/07, Johan Compagner <[EMAIL PROTECTED]> wrote:
Note that provided your dependencies don't use JDK5 classes, javac
> -target 1.4 won't somehow statically link against JDK5 code. It's the
> nature of Java that all the linking is done at runtime. Provided all
> your code compiles using -target 1.4 and you didn't use the 1.5 rt.jar
> it'll all be fine.
This statement is a bit wrong.
linking (the method you invoke) is done at compile time.
for example:
StringBuffer sb1 = new StringBuffer();
StringBuffer sb2 = new StringBuffer();
sb1.append(sb2);
if you compile this with java 1.3 and run it on java 1.4
then sb1.append(sb2) will still call StringBuffer.append(Object)
and not the new method (of java 1.4) StringBuffer.append(StringBuffer)
only if you recompile it with java 1.4 then the new method is called.
But if you say that javac knows all the methods that are new for a
specific version
and does't use that when compiling (when using a old -source and -target
thing) then it should be fine.
johan