I am looking at the following code snippet in page 580
I am struggling to understand this line
The indexOf method is describe in the Javadocs as
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
But i still dont understand how it works in the above example because:
- Dog does not override the equals() method
- Dog does not implement Comparable or Comparator interfaces
Infact it would have been correct if == was used but i dont understand how equals works in this case. How exactly does indexOf find that dog is in index 0?