A method equals()(and in this respect also a method compareTo()) can become a performance access point (for example, in high traffic mode HashMap). I was wondering what kind of tricks people took to optimize these methods for these cases when they prove the need.
IntelliJ IDEA, for example, generates the following:
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
...
}
What else do you mean, this could be a guideline for writing a good method equals()?
source
share