Results 1 to 2 of 2
Thread: == is same as .equals()??
- 09-30-2009, 03:52 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 10
- Rep Power
- 0
- 09-30-2009, 04:57 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,540
- Rep Power
- 11
Equality - as Orwell famously observed - is a matter of interpretation.
Say you found a $100 note in the street and, the next day, found the same thing. Are they really "the same"? Mostly we would say they are: they both have the same value and all that matters with banknotes is that value. They are equal.
Not so if were worried about the actual - physical - bank notes themselves. If they were stolen in a robbery, say. Then it might be very significant if a $100 note spent by a "suspect" as "the same as" one of the stolen ones.
In general the class itself will define what "equality" - or being the same - means. It does this with its .equals() method.
== tests whether two references refer to the same object in a very strong sense: that of identity. If the objects were created with different uses of "new" then they will not compare equal with ==. This test has nothing to do with what the type itself defines equality to be.Last edited by pbrockway2; 09-30-2009 at 05:00 AM.
Similar Threads
-
equals method
By mani_miit in forum Advanced JavaReplies: 7Last Post: 09-09-2009, 10:26 PM -
equals method
By timkd127 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:52 PM -
Does retainAll use equals ?
By Paul Richards in forum Advanced JavaReplies: 1Last Post: 10-27-2008, 08:17 PM -
a little problem with (equals)
By gamilah in forum New To JavaReplies: 5Last Post: 10-25-2008, 04:08 AM -
name clash: equals(E) in and equals(java.lang.Object)
By AdRock in forum New To JavaReplies: 0Last Post: 01-25-2008, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks