public static void main(String[] args) {
String s = null;
s += "word";
System.out.println("Hello "+s);
}
经测试,最后结果为 Hello nullword ,可是这是为什么呢
经考证,s = s+"word"; //在这一步先对s转字符串,如果s是对象,调用toString(),如果是null,转字符串就是"null",与"word"相加就是nullword
另:在java中运算顺序:从左向右。