On Sat, 14 Aug 2004, Richard Welty wrote:

> the authors of 98%-99% of all introductory java textbooks have
> a lot to answer for. my favorite example of the lot is that
> they all teach programmers to use String in the following manner:
> 
>    String query
>      = "SELECT foo "
>      + "FROM bar "
>      + "WHERE baz = 'bletch';"
> 

There is actually nothing wrong with this particular example.  I realize
you are pointing out an issue that can happen, so this is a just "for the
record" post.  In this case the concatenation is done at compile time.  
See:

http://www.java-performance-portal.org/article6.html

Further the usage of string concatenation is easier to read/write so you 
need to actually consider wether the code in question is actually a 
hotspot and worth StringBuffer(ifying).  Again your example is pointing to 
a database query in which case so many other things are going on it's 
unlikely to make any performance difference.

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to