Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25363
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: StringBuilder.append and CharSequence |
| Date | 2013-09-26 20:48 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnl497c6.mol.avl@gamma.logic.tuwien.ac.at> (permalink) |
| References | <slrnl45s71.mol.avl@gamma.logic.tuwien.ac.at> <52438692$0$292$14726298@news.sunsite.dk> <slrnl48tkb.mol.avl@gamma.logic.tuwien.ac.at> <52448f70$0$303$14726298@news.sunsite.dk> |
Arne Vajhøj <arne@vajhoej.dk> wrote: > On 9/26/2013 2:01 PM, Andreas Leitgeb wrote: >> Arne Vajhøj <arne@vajhoej.dk> wrote: >>> On 9/25/2013 10:19 AM, Andreas Leitgeb wrote: >>>> Is it safe to use "stringBuilder.append(this);" 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() ? >>> <quote> >>> The principal operations on a StringBuilder are the append and insert >>> methods, which are overloaded so as to accept data of any type. Each >>> effectively converts a given datum to a string and then appends or >>> inserts the characters of that string to the string builder. >>> </quote> >>> >>> Based on the use of "string" and "and then" I interpret this as: >>> <interpretation> >>> Append has two distinct sequential phases: >>> 1) convert the argument to an instance of java.util.String I only noticed this now: "java.util.String" - is that a typo for java.lang.String, or is there really a (non-public) java.util.String? >>> 2) append that to the StringBuilder >>> </interpretation> >> >> If .append() used .toString(), then there wouldn't be a point for offering >> a CharSequence overload. It could then just offer one overload for Object >> (apart from those for primitive types), and be set. > Yes. But "convert the argument to an instance of java.util.String" is > not the same as calling .toString() append() might create a snapshot-copy of the CharSequence, and it doesn't matter if that is in some extra non-public class, a simple char[] or the well-known java.lang.String. What *does* matter (at least to me, who started this thread) is, whether it uses Object.toString() or the specific CharSequence methods to obtain that snapshot. Although the docs aren't explicit on this, they now appear to imply it well enough for me to firmly believe the latter. Mostly, because the docs for append(Object) *are* explicit about using String.valueOf(obj) (and thus indirectly toString(), unless null)
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