-
Bug
-
Resolution: Duplicate
-
P1
-
None
-
1.2.1
-
x86
-
windows_nt
Name: tb29552 Date: 06/28/99
/*
If this code sample is compiled using:
jvc(Microsoft compiler) or
bcj(JBuilder compiler) or
javac from jdk1.0.2
javac from jdk1.1.x
Then the output of running the .class file (with any runtime
version) will be:
s='949500000000000'
However, if this code is compiled using javac (including the
Early Access javac-ea compiler) from 1.2.x, the output will be
something like:
s='9495[C@fe655feb0'
It appears that the .class from the 1.1.x compiler is including
the contents of the char [] in the string concatenation, whereas
the 1.2.x compiler is using the object identifier instead.
I don't see this change in behavior documented on the
compatability page at:
http://java.sun.com/products/jdk/1.2/compatibility.html
but perhaps I'm missing something.
Related reading:
"String Concatenation Operator +"
http://java.sun.com/docs/books/jls/html/15.doc.html#39990
"public String toString()"
http://java.sun.com/docs/books/jls/html/javalang.doc1.html#13783
"An Array of Characters is Not a String"
http://java.sun.com/docs/books/jls/html/10.doc.html#25726
*/
class stringTest {
public static void main(String[] args) {
char[] buf = new char[11];
for (int i = 0; i < buf.length; i++) {
buf[i] = '0';
}
String s = "9.495E11";
s = s.substring(0, 1) + s.substring(2, 5) + buf + "0";
System.out.println("s='" + s + "'");
// System.out.println(buf);
}
}
(Review ID: 84861)
======================================================================
- duplicates
-
JDK-4196269 bad code generated for string concatenation
-
- Closed
-
- relates to
-
JDK-4071548 Implicit conversion of char[] to String (for +) does not use Object#toString()
-
- Closed
-