PROPOSAL: Simplified StringBuffer/StringBuilder syntax

Joseph D. Darcy Joe.Darcy at Sun.COM
Thu May 14 22:41:31 PDT 2009

Catching up on proposals...

Derek Foster wrote:
> Simplified StringBuffer/StringBuilder syntax.
> AUTHOR: Derek Foster
> The Java language is designed to use immutable strings. Strings are intended to be constructed via one of two builder classes: StringBuffer (older, and slower due to synchronization) and StringBuilder (newer, and faster). Using these classes can make constructing Strings out of multiple pieces considerably more efficient than repeatedly concatenating strings together. These classes are often used by the Java compiler to concatenate strings behind the scenes, so that an expression like this:
>     String foo = "abcd" + 42 + "efgh";
> might be compiled as:
>     String foo = new StringBuilder("abcd").append(42).append("efgh");

The subset of this proposal I'm most sympathetic to is having ""+=" on 
StringBuffer and StringBuilder desugar into a call to append.  Offhand, 
I think that could be a mostly localized specification change that 
indicated the String{Buffer, Builder} was being mutated.  Coming up with 
String => StringBuffer conversion rules in assignment contexts is 
possible, but not necessarily desirable IMO.

An analysis of the applicability of just this change to a corpus of code 
might be informative.


More information about the coin-dev mailing list