Java idioms, their implementation, and their usage
In addition to serving as a means of communication among professionals, programming idioms are also proven programming solutions and common practices not directly derived from the language specification but born out of the programming experience. In this section, we are going to discuss the ones that are used most often. You can find and study the full list of idioms in the official Java documentation (https://docs.oracle.com/javase/tutorial).
The equals() and hashCode() methods
The default implementation of the equals()
and hashCode()
methods in the java.lang.Object
class looks as follows:
public boolean equals(Object obj) {
return (this == obj);
}
/**
* Whenever it is invoked on the same object more than once during
* an execution of a Java application, the hashCode method
* must consistently return the same integer...
* As far as is reasonably practical, the hashCode method...