Question: While assisting a student with a university project, we worked on a Java exercise provided by the university which defined a class for an address with the fields:

```
number
street
city
zipcode

```

And it specified that the equals logic should return true if the number and zip code match.

I was once taught that the equals method should only be doing an exact comparison between the objects (after checking the pointer), which makes some sense to me, but contradicts with the task they were given.

I can see why you would want to override the logic so that you can use things like `list.contains()` with your partial matching but I'm wondering if this is considered kosher, and if not why not?

Answer: 
Equality is a matter of context. Whether or not two objects are considered to be equal is as much a question of context as it is of the two objects involved. 

So, *if* in your context it makes sense to ignore city and street, then there is no problem to implement equality solely based on ZIP code and number. (As was pointed out in one of the comments, ZIP code and number *are* enough to uniquely identify an address in Brazil.)

Of course, you should make sure to follow the proper rules for overloading equality, such as making sure you also overload `hashCode` accordingly.
An equality operator will claim that two objects are equal if and only if they should be considered equal, due to whatever considerations that you find useful. 

I’ll repeat that: Due to whatever considerations that you find useful. 

The software developer is in the driver’s seat here. Apart from being consistent with obvious requirements (a=a, a=b implies b+a, a=b and b=c implies a=c) and consistency with the hash function) the equality operator can be whatever you like.