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


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

Re: Object copies?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!news2.euro.net!feeder.news-service.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From markspace <-@.>
Newsgroups comp.lang.java.help
Subject Re: Object copies?
Date Sun, 31 Jul 2011 16:47:58 -0700
Organization A noiseless patient Spider
Lines 35
Message-ID <j14pjj$r01$1@dont-email.me> (permalink)
References <j14moo$5cf$1@dont-email.me> <gfKdnX26Z5AseajTnZ2dnUVZ_jednZ2d@earthlink.com> <j14p12$nkv$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sun, 31 Jul 2011 23:48:03 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="27649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19YEQWfivqeJGyFZtg4cE/Wln1TaEX6jKE="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0
In-Reply-To <j14p12$nkv$1@dont-email.me>
Cancel-Lock sha1:AdFxR79cl/miu+3LId7nhgx45Do=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:913

Show key headers only | View raw


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.

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