I'm not sure anyone will know the answer to this question, unless you are responsible for writing the Jave API, but when the Java API says "equals", does it always mean that a.equals(b)
evaluates to true
, or sometime does it mean a == b
is true
? I have recently extended a class and wondered if I needed to override a method depending on where or not it used ==
or .equals
. Specifically, I extended javafx.beans.binding.ObjectExpression and was curious about the .isEqualTo(Object other)
method. I checked the source (here) and found that this method uses .equals
for comparison. I'm curious if I can be confident that when I read things like
"Creates a new BooleanExpression that holds true if this ObjectExpression is equal to a constant value."
that the method is not using the ==
operator. Although, as I think of it, the API can't possibly mean .equals
either, since (for example)
String constant = "constant";
ObjectExpress<String> stringExpression = new MyStringExpression("constant");
constant.equals(stringExpression)
will always evaluates to false. So maybe my question should be "when the API says 'equals', does it always refer to the most reasonable way to apply .equal
or sometime does it refer to the analogous way to apply ==
?"
EDIT
I think based on the answers I should clarify: this is not a question about the difference between ==
and .equal
. It is about to which the Java API is referring when it uses the English word "equals".