To demonstrate what is the difference between object hash code and object equal, I would like to start with a simple example in Python.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 class Person: def __init__(self, name: str, age: int) -> None: self.name = name self.age = age def __repr__(self) -> str: return f'{self.name} {self.age}' john = Person('John', 18) eventRegister = {} # John want to join the event eventRegister[john] = True # In the next day, # he changes his mind john = Person('John', 18) eventRegister[john] = False print(f'registers: {eventRegister}') # Check john = Person('John', 18) print(f'Will John join the event? {eventRegister[john]}') It’s quite simple, right? I define a new Person class that has two properties age and name. And then I defined a map, to check if a person join the event or not.
...