StringBuffer使用append提示String concatenation as argument to 'StringBuffer.append()' call

34 篇文章 0 订阅

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







评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神神的蜗牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值