Re: StringBuffer/StringBuilder efficiency
- From: Tom Anderson <twic@xxxxxxxxxxxxxxx>
- Date: Sun, 27 Sep 2009 12:59:10 +0100
On Sat, 26 Sep 2009, Patricia Shanahan wrote:
Tom Anderson wrote:
...
Oh, and you could make it a List<CharSequence>, and only toString things if they aren't instanceof CharSequence. The main effect of that is that you can append things like StringBuffers and CharBuffers directly, without having to toString them....
Doing that would need to be very carefully documented, and lead to inconsistent behavior. Appending something that is not a CharSequence would capture its toString() result as of the time of the append. Appending a CharSequence would capture its toString() as of the time of extraction of the concatenated string.
Ah yes, very good point!
If this was python, i'd think about modifying appended StringBuilders at runtime to intercept any attempts to modify them, to run a hook which would copy the original contents to a string for appending purposes before removing the interception code and carrying on with the append, but fortunately, such madness is not possible in java.
tom
--
Don't believe his lies.
.
- References:
- StringBuffer/StringBuilder efficiency
- From: Wojtek
- Re: StringBuffer/StringBuilder efficiency
- From: Roedy Green
- Re: StringBuffer/StringBuilder efficiency
- From: Lew
- Re: StringBuffer/StringBuilder efficiency
- From: Roedy Green
- Re: StringBuffer/StringBuilder efficiency
- From: Peter Duniho
- Re: StringBuffer/StringBuilder efficiency
- From: Roedy Green
- Re: StringBuffer/StringBuilder efficiency
- From: Tom Anderson
- Re: StringBuffer/StringBuilder efficiency
- From: Patricia Shanahan
- StringBuffer/StringBuilder efficiency
- Prev by Date: 。◕0◕。 Cheap wholesale AAA True Leather Miumiu handbags at WEBSITE --- www.fjrjtrade.com (paypal payment)
- Next by Date: Re: Writing Binaries to and Reading Binaries from Disk
- Previous by thread: Re: StringBuffer/StringBuilder efficiency
- Next by thread: Re: StringBuffer/StringBuilder efficiency
- Index(es):
Relevant Pages
|