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 来写的话,那这段代码阅读起来可就要命了,所以还是忽略这个提示了







目录
相关文章
遍历字符串,String line = xxx for(int i = 0;i<line.length();i++){system.out.println(line.chartAt(i)); 单个
遍历字符串,String line = xxx for(int i = 0;i<line.length();i++){system.out.println(line.chartAt(i)); 单个
|
5月前
|
移动开发 安全 Java
String、StringBuffer 、StringBuilder、StringJoiner
String、StringBuffer 、StringBuilder、StringJoiner
|
10月前
|
Python
TypeError: int() argument must be a string, a bytes原因
Python开发过程中,使用int()函数来转换或生成int类型的数据时,如果Python抛出并提示TypeError: int() argument must be a string, a bytes-like object or a real number, not 'complex',那么原因在于传递给int()函数的参数类型有误,正如TypeError的提示,int()函数的参数必须是string字符串(数值字符串)、类似字节对象、real number数字等,而不可以是complex复数类型的数据。
305 0
|
11月前
|
安全 编译器 测试技术
String,StringBuffer,StringBulider区别与联系
String,StringBuffer,StringBulider区别与联系
41 0
|
安全 编译器 C语言
【C++】string 之 assign、at、append函数的学习
【C++】string 之 assign、at、append函数的学习
135 0
|
安全
string null和“”的区别 str == null; "".equals(str); str.length 0; str.isEmpty();的区别
string null和“”的区别 str == null; "".equals(str); str.length 0; str.isEmpty();的区别
111 0
TypeError: cannot concatenate ‘str‘ and ‘list‘ objects
TypeError: cannot concatenate ‘str‘ and ‘list‘ objects
|
安全 Java 索引
Java底层源码——Arrays.toString(数组) & object.toString() & new String()
Java底层源码——Arrays.toString(数组) & object.toString() & new String()
99 0
成功解决AttributeError: ‘str‘ object has no attribute ‘decode‘
成功解决AttributeError: ‘str‘ object has no attribute ‘decode‘
成功解决AttributeError: ‘str‘ object has no attribute ‘decode‘
|
Java 编译器
深度剖析‘StringBuilder‘ can be replaced with ‘String‘ 提示
深度剖析‘StringBuilder‘ can be replaced with ‘String‘ 提示
1102 0
深度剖析‘StringBuilder‘ can be replaced with ‘String‘ 提示