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


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

Re: Object copies?

From markspace <-@.>
Newsgroups comp.lang.java.help
Subject Re: Object copies?
Date 2011-07-31 16:47 -0700
Organization A noiseless patient Spider
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>

Show all headers | 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