Re: Java compatibility issues (WAS: MF having issues?)



[post re-ordered]

"Sergey Kashyrin" <ska@xxxxxxxxxxx> wrote in message news:i0lPf.78$zF4.184390@xxxxxxxxxxxxxxxxx

String a = "123";
String b = "123";
if (a == b) {
/*You SHOULD reach this point*/
}

I believe (but am not sure), that the JLS (Java Language Specification) REQUIRES that this optimization be done (i.e. if you write a compiler which does NOT perform this optimization, then you are not legally allowed to call it a "Java compiler").

It's just implementation.
I'm not sure about optimization requiremens and as I can recall in java 1.1 I saw different results on a different platforms.

Might one of those platforms been the MS JVM versus Sun's JVM? Microsoft was illegally using the "Java" trademark. Sun permits people to use this trademark AS LONG AS your product conforms to their specifications and standards document where applicable. MS JVM's didn't follow the Sun's standards for JVMs, and so they weren't legally allow to call it a "JVM", but they did anyway.

I looked it up, and found the entry I was thinking of. Section 3.10.5 of the 3rd edition of the JLS:
http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.5

<quote>
Thus, the test program consisting of the compilation unit (§7.3):

package testPackage;
class Test {
public static void main(String[] args) {
String hello = "Hello", lo = "lo";
System.out.print((hello == "Hello") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello) + " ");
System.out.print((hello == ("Hel"+"lo")) + " ");
System.out.print((hello == ("Hel"+lo)) + " ");
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello"; }

and the compilation unit:

package other;
public class Other { static String hello = "Hello"; }

produces the output:

true true true true false true

This example illustrates six points:

* Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1).
* Literal strings within different classes in the same package represent references to the same String object.
* Literal strings within different classes in different packages likewise represent references to the same String object.
* Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals.
* Strings computed by concatenation at run time are newly created and therefore distinct.
</quote>

So this optimization is indeed a requirement before you can call your platform a "Java platform".

- Oliver

.



Relevant Pages

  • Re: (OT) In search of a definition
    ... primarily works under Windows XP, I am in search of a "good ... a package was NOT part of the language. ... without looking for something to formulate a hostile response from. ... use in Java is the same as its use in C or other languages. ...
    (comp.lang.cobol)
  • Re: (OT) In search of a definition
    ... a package was NOT part of the language. ... without looking for something to formulate a hostile response from. ... use in Java is the same as its use in C or other languages. ...
    (comp.lang.cobol)
  • building java rpm
    ... I am trying to build a java rpm based on the nosrc.rpm from jpackage.org ... chmod -R u+w bin CHANGES COPYRIGHT javaws lib LICENSE man plugin ... This package contains source files for %. ...
    (Fedora)
  • Re: Quirk with generics
    ... One place this has happened was when I said a Java class cannot have two methods with the same signature and different return types, Joshua Somebody accused me of being wrong, and I quoted chapter and verse from the JLS proving that Joshua was the wrong one. ... #* Creating four new source files within the package. ... #* Deleting the project, its package, and the four source files. ... #my IDE potentially disturbing the way I'd had it (current ...
    (comp.lang.java.programmer)
  • Re: find certain strings in java files not inside comments
    ... > I want to determine if there any of the following strings in a java ... > with a list of java files starting at $ARGV. ... > /* blah blah blah ... > foreach(@ARGV) ...
    (comp.lang.perl.misc)