== (still) != ".equal()"

AFB

Lifer
Jan 10, 2004
10,718
3
0
I was using a JTree to keep data that expires and then I get a list of things that can be revalidated in the tree. The items in the list are "equal()" to the items in the tree, but they aren't the same object. The items in the tree has a method to update the time expiration and a method to see if it's expired that is polled by the same thread. Well, I was trying to update the expiration time of the objects in the list, while still checking the JTree forobejcts that expired.


1.5 hours wasted - I feel owned :eek:
 

kbirger

Member
Dec 4, 2004
48
0
0
i'm not too sure what you're saying. but i believe equals is a method that is called for two icomparables that generally checks one or more fields and returns a bool.

you can have
string a = "pie";
string b = "pie";

a.equals(b) will still come out true.
then again, you only need to use equals() if you're in java. newer languages will work properly with just '=='. if you're using java and you use the ==, then it checks the pointer, even so it's not necessarily the same object.

string a, b;
a = b //string a now points to the same thing as b
a == b will return true;
 

ArmchairAthlete

Diamond Member
Dec 3, 2002
3,763
0
0
Yea, in Python == just checks the data for equality. "is" and "is not" check to see if the two identifiers are pointing to the same object.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: kbirger
i'm not too sure what you're saying. but i believe equals is a method that is called for two icomparables that generally checks one or more fields and returns a bool.

you can have
string a = "pie";
string b = "pie";

a.equals(b) will still come out true.
then again, you only need to use equals() if you're in java. newer languages will work properly with just '=='. if you're using java and you use the ==, then it checks the pointer, even so it's not necessarily the same object.

string a, b;
a = b //string a now points to the same thing as b
a == b will return true;

Don't worry. He knows the difference :) He's just venting because he made a silly mistake.