Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.fsmpi.rwth-aachen.de!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: Fri, 27 Sep 2013 13:45:25 -0700 Organization: A noiseless patient Spider Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 27 Sep 2013 20:45:29 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="9185b88a2b5381a82810209530bb8295"; logging-data="22936"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Fv1iEvgHtN/QTCwVA+WmVg31wYl+P++E=" 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:RUBxMw2wy5TND/maNmuI+MMhWzY= Xref: csiph.com comp.lang.java.programmer:25376 On 9/27/2013 10:31 AM, Daniele Futtorovic wrote: > On 2013-09-27 15:30, Andreas Leitgeb allegedly wrote: >> Daniele Futtorovic wrote: >>> I'd make the toString() as follows to be on the safe side: >>> char[] cs = new char[ m_len ]; >>> Arrays.fill( cs, m_ch ); >>> return new String(cs); >> >> If this is the ONLY safe side, then there wouldn't be a point >> in implementing a CharSequence in the first place for my task. > > Why not? The Standard API's StringBuilder#append(CharSequence), AFAICS, > does not call toString() -- granted, the JavaDoc stipulates nothing to > that effect. I read Andreas's comment as "there's not point introducing a new type if a repeated string is just always turned into a regular String anyway." If your new type can be easily replaced with a static method: public static String repeated( char c, int count ) { final char[] ca = new char[ count ]; Arrays.fill( ca, c ); return new String( ca ); } Then there's really no need to introduce a new type. However I'm not 100% confident that I'm following his line of thought.