I wanted to clarify if I understand this correctly:
==is a reference comparison, i.e. both objects point to the same memory location.equals()evaluates to the comparison of values in the objects
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general, the answer to your question is “yes”, but…
.equals(...)will only compare what it is written to compare, no more, no less.equals(Object o)method of the closest parent class that has overridden this method.Object#equals(Object o)method. Per the Object API this is the same as==; that is, it returns true if and only if both variables refer to the same object, if their references are one and the same. Thus you will be testing for object equality and not functional equality.hashCodeif you overrideequalsso as not to “break the contract”. As per the API, the result returned from thehashCode()method for two objects must be the same if theirequalsmethods show that they are equivalent. The converse is not necessarily true.