A workable approach to handle that situation may be to have the base type implement an equals2 method, which return 1 if its special knowledge of the other object meant it could tell it was equal, -1 if it could tell it was not equal, or 0 if it couldn't tell. If either type's equals2 method knows they're unequal, they're unequal. Otherwise, if
So it is using the .equals() method from its parent "Object" class. In the object class .equals() has been written to check the reference equality. Note that sb3.equals(sb4) will return "true" in case of String. Because .equals() method has been overridden in String class to check and match the content of two different Strings. Parameters: Obj - The object to compare with. Return Value: This method returns a Boolean value, It returns true, if the Boolean objects represent the same value. It returns false, if the Boolean objects represent different value. If a.equals(b) == true and a.equals(c) == true, then b.equals(c) must also return true. Persistence. The result of equals() must change only when the fields involved are changed. Using the Not Equals Operator With equals () We can use the ! operator with the equals () method to check if the contents of the variables match or not. In the example, we take two String variables. In the if condition, we check the str1.equals (str2) with a ! operator at the beginning. The ! operator makes the result opposite, which means ifThe equals () method is a method of Integer class under java.lang package. This method compares the value of the parameter to the value of the current Integer object. It returns Boolean (True or False) which corresponds to the equality of this Integer and method argument object. It also overrides the equals () method of Object class.
You'll need to cast other to a Pokemon object (and use instanceof) if you want to use methods and member variables specific to the Pokemon class. You need this override if you want other JDK (or even your own) code that uses .equals() to call your custom .equals() method, instead of the base Object.equals() one.