Re: [問題] Java型別轉換

看板java作者 (._.)時間16年前 (2009/07/15 09:12), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
※ 引述《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)

07/15 10:39, , 1F
concatenation 翻成"串接"應該比較適當。
07/15 10:39, 1F
文章代碼(AID): #1ANIq1aE (java)