您的位置:首页 > 编程语言 > Java开发

Java Puzzlers笔记--puzzle 10: Tweedledee += 问题(2)

2007-03-03 19:18 495 查看
 x = x + i;
but this is not:
x += i;

Solution:
 Objext x = "Buy ";
 Stirng i = "Effective java!";
 x = x + i;//it's legal.显示:But Effective java!
 x += i; //it's illegal.因为+=操作符没有对String类型的定义。

TID:
 The += operator allows its right-hand operand to be of any type if the variable on

the left-hand side is of type String, in which case the operator performs string

concatenation.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java string