Java’s object equality

Maybe I’m just a dinosaur.

In java, the “==” operator tests for true object equivalence, i.e. “Is this object the very same object as that one.”

I NEVER mean this. This is NEVER the result I want. I want to know if object a contains precisely the same thing as object b.

For instance:

String a = “foobar”;
String b = “foobar”;

“if (a == b) “

returns false.

Yes, I’m just not used to java. But in c++ if I want “==” to mean what I think it should mean I can just make it mean that. in Java, the solution is “well, no you have to call something else, sometimes it’s a method on the object called ‘equals’, but not always.”

*grumpf*

Tags:

Leave a Reply