Replace concat String to append in StringBuilder parameters
Andrej Golovnin
andrej.golovnin at gmail.com
Mon Aug 11 13:12:02 UTC 2014
Hi,
About readable of code I just renamed this class to sb instead of buf,
> strbuf, etc.
>
I doubt that renaming variables does really improve the code readability.
And you changed the indentation (take look at other classes too):
239 public String toString() {
240 StringBuilder sb = new StringBuilder();
241 sb.append("init =
").append(init).append('(').append(init >> 10)
242 .append("K) ");
243 sb.append("used =
").append(used).append('(').append(used >> 10)
244 .append("K) ");
245 sb.append("committed = ").append(committed).append('(')
246 .append(committed >> 10).append("K) ");
247 sb.append("max = ").append(max).append('(').append(max
>> 10)
248 .append("K)");
249 return sb.toString();
250 }
Because using StringBuilder beyond be more explicit I can use char instead
> of a single String.
>
In the most classes I mentioned in my previous mail only the
#toString()-methods would be affected by the proposal. And in the most
cases, maybe in all cases, the #toString()-methods in this classes exists
only to provide nice output. I would not consider them
performance-critical. Btw. I see here a nice opportunity to create an RFE
for the Javac team. Following code:
Object o1 = ...;
Object o2 = ...;
String s = "abc" + o1 + "c" + o2 + "\n";
should be translated to:
String s = new
StringBuilder().append("abc").append(o1).append('c').append(o2).append('\n').toString();
instead of:
String s = new
StringBuilder().append("abc").append(o1).append("c").append(o2).append("\n").toString();
Best regards,
Andrej Golovnin
>
>
> https://dl.dropboxusercontent.com/u/16109193/open_jdk/string_builder_concat_3.zip
>
>
> On Mon, Aug 11, 2014 at 7:56 AM, Pavel Rappo <pavel.rappo at oracle.com>
> wrote:
>
>> > In the class
>> > src/share/classes/javax/management/openmbean/CompositeType.java you have
>> > added the
>> > annotation
>> @SuppressWarnings("StringConcatenationInsideStringBufferAppend")
>> > instead of fixing the concatenation inside the append method. Why?
>>
>> +1 Moreover, I wonder where this value comes from? I've never seen it
>> before. Here are warnings that javac supports:
>>
>>
>> all,auxiliaryclass,cast,classfile,deprecation,dep-ann,divzero,empty,fallthrough,finally,options,overloads,overrides,path,processing,rawtypes,serial,static,try,unchecked,varargs
>>
>> It doesn't look like one of Eclipse's warnings either.
>>
>> > And I would like to suggest to drop explicit usage of StringBuilder in
>> some
>> > methods at all to improve code readability.
>>
>> Agree.
>>
>> -Pavel
>>
>>
>
>
> --
> Otávio Gonçalves de Santana
>
> blog: http://otaviosantana.blogspot.com.br/
> twitter: http://twitter.com/otaviojava
> site: *http://about.me/otaviojava <http://about.me/otaviojava>*
> 55 (11) 98255-3513
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/security-dev/attachments/20140811/67c78c55/attachment.htm>
More information about the security-dev
mailing list