Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #914

Re: Object copies?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Knute Johnson <september@knutejohnson.com>
Newsgroups comp.lang.java.help
Subject Re: Object copies?
Date Sun, 31 Jul 2011 17:14:47 -0700
Organization A noiseless patient Spider
Lines 45
Message-ID <j14r5f$2i8$1@dont-email.me> (permalink)
References <j14moo$5cf$1@dont-email.me> <gfKdnX26Z5AseajTnZ2dnUVZ_jednZ2d@earthlink.com> <j14p12$nkv$1@dont-email.me> <j14pjj$r01$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 1 Aug 2011 00:14:39 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="2632"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mjHj87v1ofOhkHeOJsbXi"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0
In-Reply-To <j14pjj$r01$1@dont-email.me>
Cancel-Lock sha1:g3n6aR875Xmb2CBGiTIHifGJwBg=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:914

Show key headers only | View raw


On 7/31/2011 4:47 PM, markspace wrote:
> On 7/31/2011 4:38 PM, Knute Johnson wrote:
>
>> On 7/31/2011 4:26 PM, Patricia Shanahan wrote:
>>> FindBugs is probably complaining because you probably do not need to
>>> copy. Remember that none of the String methods modifies the String on
>>> which it is called.
>
>
>> Light Bulb! All I need is another set of references.
>
>
> Yeah, I was going to say the same as Patricia. Strings are immutable,
> always. Why do you need to make a copy?
>
> Also, what is this for? Some sort of before-and-after object, like a
> Command that can be reverted? Just save the original and the new:
>
> class StringModification implements Command {
>
> private final String before, after;
>
> public StringModification( String before, String after ) {
> this.before = before; this.after = after;
> }
>
> public String revert() { return before; }
>
> }
>
> Invoke with:
> new StringModification( str, str.replace(...) );
>
> or similar. Actually for this particular application, all you probably
> need to save is the "before" bit, but you did ask for a copy of both.
>

Thanks.

There are days when the simplest things don't seem so obvious any more. 
  I've been having one of those years.

-- 

Knute Johnson

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Object copies? Knute Johnson <september@knutejohnson.com> - 2011-07-31 15:59 -0700
  Re: Object copies? Patricia Shanahan <pats@acm.org> - 2011-07-31 16:26 -0700
    Re: Object copies? Knute Johnson <september@knutejohnson.com> - 2011-07-31 16:38 -0700
      Re: Object copies? markspace <-@.> - 2011-07-31 16:47 -0700
        Re: Object copies? Knute Johnson <september@knutejohnson.com> - 2011-07-31 17:14 -0700
  Re: Object copies? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-01 08:45 -0700

csiph-web