Object equality is context sensitive

Equality is context sensitive. It’s very rarely as cut-and-dried as people think it is.

As a simple example, consider two $5 notes. I think everyone can agree that these notes have the same value – they are both worth $5. But are they equal?

Continue reading “Object equality is context sensitive”

Java, Equality, Mutability

TL;DR version: Don’t implement equals() on mutable objects.

This is a post I’ve been tossing around for a couple of years, ever since a lunchtime debate with a colleague. It’s a simple statement: You shouldn’t implement the equals() method if your object isn’t immutable.1

Continue reading “Java, Equality, Mutability”

%d bloggers like this: