StringBuffer使用append提示String concatenation as argument to 'StringBuffer.append()' call
昨天發現一個IDE提示:
String concatenation as argument to 'StringBuffer.append()' call less... (Ctrl+F1)
Reports String concatenation used as the argument to StringBuffer.append(),StringBuilder.append() orAppendable.append(). Such calls may profitably be turned into chained append calls on the existingStringBuffer/Builder/Appendable, saving the cost of an extraStringBuffer/Builder allocation.
This inspection ignores compile time evaluated String concatenations, which when converted to chained append calls would only worsen performance.
這段英文看的意思不是很明白怎麼回事,
str.append("Date: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "\n"); str.append("Version: " + info.versionName + "(" + info.versionCode + ")\n");
代碼大概是這樣的後麵還有很多 append 。
後來我才反應過來,是裏麵的參數的問題。
本來 append 方法就是拚接字符串用的,而參數裏麵又用了 + 加號來拚接字符串,於是就提示你應該用 append 將這些字符串作為參數來使用~~~
不過如果真的全用 append 來寫的話,那這段代碼閱讀起來可就要命了,所以還是忽略這個提示了
最後更新:2017-04-03 12:55:32