Answer to Question #165628 in Java | JSP | JSF for Agnès Duhamel

Question #165628

The class Object defines an equals() method to compare objects.

Specify the advantages and disadvantages of using this method and suggest an alternative for equality


1
Expert's answer
2021-02-22T16:06:24-0500

The equal method of the Java class is used to compare the equality of two objects. The main advantage of the equal method is that it is easy to use. This is possible especially if the objects being compared belong to the superclass.

if no inheritance is used.

Its main disadvantage is that with the use of inheritance, the programmer needs to override the equal method. This necessitates the need for additional code in the program.

Another disadvantage of using equals is that the program will not throw any exceptions if the equals() and hashCode() contract is violated

An alternative to using the equals method of Object class is usually to write your own code to perform the same.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog