[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String.equals optimisation

From: Per Bothner
Subject: Re: String.equals optimisation
Date: Mon, 11 Jul 2005 23:13:01 -0700
User-agent: Mozilla Thunderbird 1.0.2-6 (X11/20050513)

Stephen Crawley wrote:
address@hidden said:

I'd be interested to hear of other reasons for Java's requirement to
intern all literal strings and constants.

Backwards compatibility.

At this point we can only conjecture as to why Java was originally defined this way. My guess is that this decision was made in the early days when
the language was being targeted at embedded computing and machines with
not a lot of memory.  Having the JVM do interning of literals could save
enough memory to matter.

Er, no.

String literals in JDK 1.0 were *not* interned.
That was changed in JDK 1.1.

The world has moved on, and nobody thinks much about conserving string space these days.

I don't believe saving space was the motivation, but consistency.

static String x = "a";
static String y = "a";

Then you had (x==y) if x and y were defined in the same class, but
(x!=y) in they were defined in different classes.

People expect that ("a"=="a").
        --Per Bothner

reply via email to

[Prev in Thread] Current Thread [Next in Thread]