Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!weretis.net!feeder1.news.weretis.net!newsfeed.CARNet.hr!garrison.bnet.hr!gregory.BNet.hr!not-for-mail From: Josip Almasi Newsgroups: comp.lang.java.programmer Subject: Re: Java blunders Date: Tue, 29 Jul 2014 00:11:26 +0200 Organization: B.net Hrvatska d.o.o. Lines: 43 Message-ID: References: <53cef75d$0$291$14726298@news.sunsite.dk> <7s6vs9p395bretqrtdvh9i6til83vfk52p@4ax.com> <53d04b5f$0$291$14726298@news.sunsite.dk> NNTP-Posting-Host: cpe-188-252-131-105.zg5.cable.xnet.hr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: gregory.bnet.hr 1406585486 4476 188.252.131.105 (28 Jul 2014 22:11:26 GMT) X-Complaints-To: abuse@globalnet.hr NNTP-Posting-Date: Mon, 28 Jul 2014 22:11:26 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:29415 On 07/28/2014 10:39 PM, Eric Sosman wrote: > On 7/28/2014 4:23 PM, Josip Almasi wrote: >> I think you guys missed worst thing with java concatenation, and it's >> got nothing to do with operator. >> It's about how operator gets interpreted: >> >> out.println ( new StringBuffer("the answer is ").append(new >> StringBuffer(a + b)).append(new StringBuffer(".")); > > Why do you think this is so? OK you had me look at the spec:) String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. > javac 1.8.0_11 compiles it to > the equivalent of > > out.println(new StringBuilder() > .append("the answer is ") > .append(a + b) > .append(".") > .toString()); > > ... and I think all javac's have done so for a long time (but I > don't have them available for checking). > >> It's three new objects, all synchronized. > > ... for suitable values of "three" (i.e., 2) and "all" (0). > >> OK I haven't read the spec for a while but that's it IIRC, spec requires >> it that way. > > StringBuilder replaced StringBuffer for this purpose in Java 1.5, > just under ten years ago. I guess that counts as "a while." ;-) Indeed:) I stand corrected. Regards...