Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: StringBuilder.append and CharSequence Date: Wed, 25 Sep 2013 13:02:10 -0700 Organization: A noiseless patient Spider Lines: 20 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 25 Sep 2013 20:02:15 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="9185b88a2b5381a82810209530bb8295"; logging-data="722"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ly/pBgjjqFXHK4V+P2nAJr0djSeCyJT0=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 In-Reply-To: Cancel-Lock: sha1:GWst44DzmrnMYBj8Kpktv9LQpRU= Xref: csiph.com comp.lang.java.programmer:25337 On 9/25/2013 7:19 AM, Andreas Leitgeb wrote: > Is it safe to use "stringBuilder.append(this);" It wasn't clear to me either from reading the Java docs that the above was safe, so I'd avoid it. > in a CharSequence > implementation's .toString(), or could this lead to a recursive > loop, if some version of a Java class library implements the > append() for CharSequence by using it's toString() ? That paragraph wasn't clear to me at all. I was going to suggest toString() as the safe approach. stringBuilder.append( this.toString() ); This seems bomb proof to me, as the string is constructed before the method call. Did I miss something?