[5111] in java-interest
Re: Strings.substring() and the == operator
daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Mon Jan 29 15:17:15 1996
Date: Mon, 29 Jan 1996 10:48:24 -0800
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: mikep@exmachina.com
Cc: java-interest@java.Eng.Sun.COM
Hi Michael,
> At 05:23 AM 1/28/96 -0600, you wrote:
> >
> >
> >On Sun, 28 Jan 1996, Walter Szewelanczyk wrote:
> >
> >"==" is a test for identity not for equality.
> >You should always use equals() instead.
> >
>
> I'm glad you pointed this out.
>
> This is inconsistent and, in my opinion, a bad choice of behaviour
> for the equality operator (==) on strings.
But! There is a reason for this. Equality and Identity are both
useful. You need both in a system where you have value objects
that are passed by value as well as object that are passed
by reference.
Lisp used to have an "eq" and an "equals" operator one checked
equality the other identity, I can't remember which is which.
Would that have been a better solution? I think not.
> Will "intX == intY" return false if they refer to separate memory
> locations? Of course not.
No. Integers are defined to be passed by value, not by reference.
> Why did you do this to us, Arthur?
It wasn't just me!
Have fun,
Arthur van Hoff
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com