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

    技术2022-05-11  69

     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.


    最新回复(0)