Re: comparing strings with ==

Date view Thread view Subject view Author view

From: Tim Wilkinson (tim@transvirtual.com)
Date: Thu Sep 03 1998 - 15:53:09 EDT


Strings can be 'intern'ed in which case you can then come them using ==, but
this doesn't happen automatically (I'm not sure how it could without help from
the compiler - how to you magic new String("hello") into it's intern, and does
the compiler automatically intern quoted strings in source.

For now, I'd just fix to use 'equals'.

Tim

Archie Cobbs wrote:

> Archie Cobbs writes:
> > Does kaffe keep all String objects unique so that you can do this?
> >
> > + if (protocol == "ftp") {
> > + port = 21;
> > + }
> >
> > That's cool if it does... then can't we simplify String.equals() ?
>
> A quick look at String.java shows that Strings are not "uniqified",
> in which case java.net.URL.getDefaultPort() (whence this code snippet came)
> is broken.
>
> Would it be useful to change Kaffe to uniquify all strings (via
> some sort of hashtable (possibly optimized with native code))?
> I sortof remember that newer JDK's provided this (so you could
> compare strings with ==).
>
> Also, what's the status of INTERN_UTF8CONSTS and how does that
> relate to this?
>
> Curious,
> -Archie
>
> ___________________________________________________________________________
> Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com

--
  Tim Wilkinson                         Tel:     +1 510 704 1660
  Transvirtual Technologies, Inc.,      Fax:     +1 510 704 1893
  Berkeley, CA, USA.                    Email:   tim@transvirtual.com


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 19:56:54 EDT