閱讀477 返回首頁    go 技術社區[雲棲]


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

  上一篇:go 將一個int類型變量(4字節), 以二進製形式進行輸出--showbits.c
  下一篇:go 更相損減法和輾轉相除法 求最大公約數和最小公倍數(C語言)