作者ogamenewbie (._.)
看板java
标题Re: [问题] Java型别转换
时间Wed Jul 15 09:12:30 2009
※ 引述《iamtops (Tops)》之铭言:
: 1 public class TestString{
: 2 public static void main(String argv[]) {
: 3 String str = "5566";
: 4 str = str+24;
: 5 System.out.print(str);
: 6 }
: 7 }
: 请问一下这样输出结果为什麽会是556624呢
: "5566"不是在string pool中了吗?
: 这样不是应该会是应该会有错误产生?
: 另外请问一下Java 有自动型别转换吗
: 谢谢
http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#186035
5.4 String Conversion
String conversion applies only to the operands of the binary + operator when
one of the arguments is a String. In this single special case, the other
argument to the + is converted to a String, and a new String which is the
concatenation of the two strings is the result of the +. String conversion is
specified in detail within the description of the string concatenation +
operator (§15.18.1).
String Conversion 只会在 + 号运算且其中一个引数是 String 时发生。在这
种特殊情况下,另外一个引数会被转换成 String , + 号合并产生另外一个新
的 String 。 15.18.1 有更详细叙述。
随手翻译的,上面三行翻译有错的,该鞭的,不用客气就鞭吧。 请了。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 120.125.83.125
※ 编辑: ogamenewbie 来自: 120.125.83.125 (07/15 09:13)
1F:→ sbrhsieh:concatenation 翻成"串接"应该比较适当。 07/15 10:39