> -----Original Message-----
> From: Magesh Umasankar [mailto:[EMAIL PROTECTED]
> > 2) the static strings will be concatenated at compile time
> as there is no
> > variables here. check the bytecode with javap
> >
>
> oh! Something new to learn everyday -
> thanks for clarifying - forget my earlier
> comments, Stefan ;-)
Actually the string concatenation might be 'slightly' different depending on
the version of the java compiler and its version but this is what happens so
far it might depend 'where' is the variable in the concatenation to
completely break the compiler 'optimization'. (which is close to absolute
zero now since JDK 1.2 anyway)
from the top of my head you may have something like this:
"aaa" + "bbb" -> "aaabbb"
"aaa" + "bbb" + z -> new StringBuffer("aaabbb").append(z).toString()
"aaa" + "bbb" + z + "ccc" -> new
StringBuffer("aaa").append("bbb").append(z).append("ccc").toString()
I also remember that in some cases one compiler may use the empty
StringBuffer ctor instead of the String one.
Your mileage may vary.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>