public boolean equals( Object other ) { return name.equals( other.getName() ); }
There is an error.
getName()
is not
a method of Object
.
You might wonder why the method is not written this way:
public boolean equals( Entry other ) { return name.equals( other.getName() ); }
This is a correct method, but it does not override
the equals(Object)
method.
The types of the parameters do not match.
To use
indexOf()
,
you must override the equals(Object)
method:
int indexOf(Object element) // Search for the first occurrence of //element
, testing for equality // using the equals(Object) method // ofelement
.
Will the following work for equals(Object)
?
class Entry { . . . . . public boolean equals( Object other ) { return getName().equals( ((Entry)other).getName() ); } . . . . . }