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: 
Although the given requirement contradicts the *human sense* it is OK to let only a subset of the objects properties define the meaning of "unique". 

Problem here is that there is a technical relationship between `equals()` and `hashcode()` so that for two objects `a` and `b` of that type is deemed to be:  

`if a.equals(b) then a.hashcode()==b.hashcode()`  

If you have a subset of the properties defining your uniqueness conditions you must use the same subset to calculate the return value of `hashcode()`.

After all the much more appropriate approach for the requirement may have been to implement `Comparable` or even a custom `isSame()` method.
Like others mentioned, on one hand equality is just a mathematical concept satisfying some properties (see e.g. [Albuquerque's](https://softwareengineering.stackexchange.com/a/403100/3850) answer). On the other hand its semantic and implementation is determined by the context. 

Regardless of the implementation details, take for example a class representing arithmetic expressions (like `(1 + 3) * 5`). 
If you implement an interpreter for such expressions using the standard evaluation rules for arithmetic expressions it makes sense to consider the respective instances for `(1 + 3) * 5` and `10 + 10` to be `equal`. 
However, if you implement a pretty printer for such expressions above instances would not be considered `equal`, while `(1 + 3) * 5` and `(1+3)*5` would.