Re: ActionEvent Performance Issue

From: Gregory A. Swarthout (gregorys_at_xmission.com)
Date: 12/18/03


Date: 18 Dec 2003 10:00:24 -0800


"Filip Larsen" <filip.larsen@nospam.dk> wrote in message news:<brqoct$2fjm$1@news.cybercity.dk>...
> Gregory A. Swarthout wrote
>
> > > If the strings have been "intern"ed using the
> > > String.intern() method, then you can safely use == to compare them.
> >
> > Not necessarily. Check out
> >
> http://www.javaworld.com/javaworld/javaqa/2003-12/01-qa-1212-intern.html
> > for the explanation on why this can't always be counted on.
>
> Would you please explain where in the article it is claimed that
> intern'ed strings not always can be compared with the == operator?

"As you can see, s1 is interned and later garbage collected. s2
represents the same string value but is re-interned as a new object.
In other words, Java does not prevent the "same" interned String from
being different objects at different times."

Since == compares object references, not the contents of the string,
it can return false under specific, deterministic situations. Why
compare Strings by a method that *almost* always returns the same
value as .equals() when .equals() itself returns the results you need
100% of the time?

Greg



Relevant Pages

  • Re: Function that returns date of file.
    ... string after the date/time when it is used by itself. ... Is that your entire script? ... I make an IF statement that required the 'equals equals'. ... designed database your job will be all that much harder. ...
    (alt.php)
  • Re: == versus .Equals()
    ... whether you use the == operator or the Equals method. ... To explain the differences I will use the String class as an example. ... the String class uses the static Equals method ... a string compare. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Catching invalid string comparisons
    ... the programmer expected it to check if it is equal to an empty string. ... compares for equality -- but two references are equal ... Comparing the objects themselves, ... requires use of the equals() method. ...
    (comp.lang.java.programmer)
  • Re: File.lastModified *extremely* slow ?
    ... > he talks of the interned String data being kept outside the heap. ... He did claim in the discussion that interned String data is kept outside ... JLS, in particular: "Literal strings within the same class in the ...
    (comp.lang.java.programmer)
  • Re: hashCode() for Custom classes
    ... I am currently faced with the task of providing a logical equals() ... have to override the hashCode() so that when an object of this class ... String name; ... The hash code of Agent is the combined hash code of ...
    (comp.lang.java.programmer)