Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25385
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: StringBuilder.append and CharSequence |
| Date | 2013-09-29 04:58 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <l2850h$9nf$1@dont-email.me> (permalink) |
| References | (4 earlier) <l227v3$f6i$1@dont-email.me> <slrnl4b22r.mol.avl@gamma.logic.tuwien.ac.at> <l24fdo$ius$1@dont-email.me> <l24qp9$mco$1@dont-email.me> <slrnl4c4di.mol.avl@gamma.logic.tuwien.ac.at> |
On 2013-09-28 01:16, Andreas Leitgeb allegedly wrote: > markspace <markspace@nospam.nospam> wrote: >> On 9/27/2013 10:31 AM, Daniele Futtorovic wrote: >>> On 2013-09-27 15:30, Andreas Leitgeb allegedly wrote: >>>> Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> 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." > > Yes, that's about it. > > The "new type" is the ChSeq from a few posts upthread. > The "repeated string" is a possibly long repetition of > just a single char, compactly represented by ChSeq... > Yes, but using the ChSeq (as it was introduced) to append it to a StringBuilder WILL NOT, as the JSE currently stands, result in the invocation of toString(). So you are safe to go. Then, as far as the implementation of toString() is concerned (which only matters if other API use your ChSeq's), I would say it ought to be implemented as above, for safety reasons and because, after all, since every String uses a char[] buffer, it stands to reason that you cannot produce a String, which toString() is supposed to do, without allocating such a buffer (as an optimisation, you could create it but once on demand). Incidentally, while I know no place in the documentation that expresses it, it is likely the case that all API designed to handle CharSequence's will operate on a by-char-basis (as opposed to calling toString() ) if they can afford it at all -- seeing how this is what the CharSequence interface is all about. -- DF.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-25 14:19 +0000
Re: StringBuilder.append and CharSequence markspace <markspace@nospam.nospam> - 2013-09-25 13:02 -0700
Re: StringBuilder.append and CharSequence markspace <markspace@nospam.nospam> - 2013-09-25 18:34 -0700
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-26 17:37 +0000
Re: StringBuilder.append and CharSequence Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-09-26 23:11 +0200
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-27 13:30 +0000
Re: StringBuilder.append and CharSequence Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-09-27 19:31 +0200
Re: StringBuilder.append and CharSequence markspace <markspace@nospam.nospam> - 2013-09-27 13:45 -0700
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-27 23:16 +0000
Re: StringBuilder.append and CharSequence Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-09-29 04:58 +0200
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-30 20:02 +0000
Re: StringBuilder.append and CharSequence Arne Vajhøj <arne@vajhoej.dk> - 2013-09-25 20:57 -0400
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-26 18:01 +0000
Re: StringBuilder.append and CharSequence Arne Vajhøj <arne@vajhoej.dk> - 2013-09-26 15:47 -0400
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-26 20:48 +0000
Re: StringBuilder.append and CharSequence Arne Vajhøj <arne@vajhoej.dk> - 2013-09-26 16:58 -0400
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-27 12:52 +0000
Re: StringBuilder.append and CharSequence Arne Vajhøj <arne@vajhoej.dk> - 2013-10-04 20:59 -0400
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-10-05 12:51 +0000
Re: StringBuilder.append and CharSequence Sven Köhler <remove-sven.koehler@gmail.com> - 2013-09-27 15:41 +0300
csiph-web