>  e> While fixing these problems, I've rewritten both of these methods
>  e> to use StringBuffer.append() instead of String concatenation for
>  e> obvious reasons.
> 
> This is what I've been taught to do once myself, but see
> <URL:http://c2.com/cgi/wiki?StringBuffer> - seems like String
> concatenation will result in the same bytecode anyway (more or less).

not quite - for every '+' operator, the compiler creates a StringBuffer, appends
the right operand, and does a toString() on the buffer. For multiple concats
(i.e., "x is " + x + " and y is" + y) you get five object creations on each '+'.
SLOOOOW.

Although, I agree with you, if the original string isn't final, I wonder why the 
compiler isn't smart enough to optimize this out. Failing that, why did Sun include
the operator at all if it's guaranteed to suck like it does?

Go fig.

Reply via email to