c******n 发帖数: 4965 | 1 I see that today a lot of people still pay extra care to change StringA +
StringB into
StringBuffer.append(). but from what I observed from de-compiled bytecode,
A + B does generate StringBuffer.append(),
so I think it's bad in most cases to manually write out StringBuffer.append(
) since javac optimizes it to append() automatically anyway, while writing "
+" for human code reading is much cleaner and nicer to the eye
what do u think? |
k**********g 发帖数: 989 | 2 Programmers are by their nature circumspect; because they cannot assume that
everything will work out fine. They must be prepared for the impossible,
because the impossible happens regularly in enterprise system logs.
It is the lack of automatic refactoring and profiling tool that causes
programmers to perpetuate the habit of bypassing compilers. |
l*********s 发帖数: 5409 | 3 it is unnecessary in many cases, but you need to know the cases when
compiler will do the optimization and when it could not. It is mentally easy
to just stick to the same rule and don't worry about exceptions. |
p*****2 发帖数: 21240 | |
s*****n 发帖数: 5488 | 5 string is immuatable.
if you use + + + +
then you use several stringbuffers and have to gc them in future.
even you just one +, still you save a temp stringbuffer obj.
that maybe a huge performance difference for a large loop.
+
append(
"
【在 c******n 的大作中提到】 : I see that today a lot of people still pay extra care to change StringA + : StringB into : StringBuffer.append(). but from what I observed from de-compiled bytecode, : A + B does generate StringBuffer.append(), : so I think it's bad in most cases to manually write out StringBuffer.append( : ) since javac optimizes it to append() automatically anyway, while writing " : +" for human code reading is much cleaner and nicer to the eye : what do u think?
|