Re: Re: JDK used for compiling
Bernhard Frauendienst <[email protected]>
| Newsgroups | gmane.linux.gentoo.java |
|---|---|
| Message-ID | <[email protected]> |
Sorry, I forgot to CC the mailing list on my last response... Please
read now:
Sven Köhler schrieb:
>> Because selecting -target 1.5 is quite sufficient. I'm not sure what you
>> meant by overloading, but 1.4 bytecode compiled with a Java 6 JDK runs
>> fine on a Java1.4 JDK.
>
> Oh i see!
>
> Now i got you - and you ran into the old mistake. I know, that it is
> common practice to compile Java-Code with "-target X.Y" and to assume,
> that it automatically run's fine with a Java X.Y VM.
>
> But i hope, that i can show to you, that this is not true. Assume you
> have the following code:
>
> public class OverloadTest
> {
> public static void main(String[] args)
> {
> CharSequence sb1 = new StringBuffer("abc");
> StringBuffer sb2 = new StringBuffer();
> sb2.append(sb1);
> System.out.println(sb2);
> }
> }
>
>
> Compile it with JDK 1.5 or higher. Use "-target 1.4".
>
> The generated class files run fine with JDK 1.5 or higher. But with JDK
> 1.4 you will get the following exception:
>
> java.lang.NoSuchMethodError:
> java.lang.StringBuffer.append(Ljava/lang/CharSequence;)Ljava/lang/StringBuffer;
> at compat.overload.OverloadTest.main(OverloadTest.java:9)
>
>
> I hope, you see, why this error had to happen. The methode
> StringBuffer.append(CharSequence) is documented is marked to be @since
> 1.5 - but this is just a JavaDoc feature. Using "-target 1.4" does NOT
> avoid, that it's actually used within the Bytecode.
>
>
> I know, that you might not have seen this issue in real life. On the
> other hand, this kind of issues go unnoticed, until the code is actually
> executed because the NoSuchMethodError is thrown AT RUNTIME.
>
>
Such packages will then be marked with RDEPEND=">=virtual/jre-1.5" and
emerging them will pull in a JRE that supports the needed features (if
not already installed). I don't see a problem there.
--
[email protected] mailing list