http://www.pellegrino.link/2015/08/22/string-concatenation-with-java-8.html
On Mon, Jun 5, 2017 at 9:20 PM, sebb <seb...@gmail.com> wrote: > On 5 June 2017 at 18:27, Felix Schumacher > <felix.schumac...@internetallee.de> wrote: > > Hi all, > > > > while looking at the javadocs for DataSourceElement, I found a couple of > > things, that look odd to me. > > > > a) Instead of string concatenation with "+" for static strings, often a > > Stringbuilder is used. So instead of: > > > > String result = "shared: " + shared + " user: " + username + ... > > > > The code looks like > > > > StringBuilder builder = new StringBuilder(40); > > builder.append("shared: ").append(shared) > > .append("user: ").append(username) > > ... > > String result = builder.toString(); > > > > I think the compiler will generate the same code for the former and the > > latter. To me the string concatenation looks cleaner. > > > > Is there any reason to use the latter code for static strings? > > Probably historic. > I think originally the Java compiler was not clever enough to use a > StringBuilder (indeed before Java 5 it did not exist). > > > b) In the inner class DataSourceComponentImpl there is some (really > minor) > > code duplication in getConnectionInfo and getConnection. But my real > concern > > is, that getConnection checks for a null BasicDataSource, while > > getConnectionInfo doesn't. > > > > What is the logic behind this? > > > > Regards, > > > > Felix > > > -- Cordialement. Philippe Mouawad.