Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Object and String parameter

I am learning through w3schools. I am confused mainly about the meaning of java syntax. To my understanding, both functions the same except for the String cases.
The thing I don’t understand is their parameters; why is the other an Object and the other is String?

public boolean equals(Object anotherObject)
public boolean equalsIgnoreCase(String anotherString)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

equals(Object) is defined in java.lang.Object and is a method that is available on all object in Java. Therefore it’s defined as generically as possible (i.e. it accepts any other object as the argument).

equalsIgnoreCase is only defined in java.lang.String. It’s a specific method for comparing strings in a specific way. Since it’s about text, it doesn’t make sense to accept any non-String object here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading