For part three in this series of four blog posts, we look at another one of Java’s “big three” methods: Object.hashCode(). This method returns an integer value that can be used to split objects into buckets. One critical requirement is that any two objects that compare as equal must return the same hash code. We explore how to meet that requirement, while also writing hashCode() methods that are effective and efficient.
Tag: bigthree
The Big Three in Java, Part Two: equals(Object)
In the second of a series of four blog posts, we explore another one of the “big three” methods in Java: the Object.equals(Object) method. This method allows us to compare two objects of a given type for value equality, instead of just reference equality. That is, this method can compare the internal state of two objects to determine if they’re equal.
The Big Three in Java, Part One: toString()
In the first of a series of four blog posts, we’ll explore one of the “big three” methods in Java: the Object.toString() method. This method generates a String representation of an object and its state. By overriding the Object.toString() method in any class that we write, we can customize, for example, how objects of that class are displayed when printed to the console.