What’s wrong with overridable method calls in constructors?

On invoking overridable method from constructors Simply put, this is wrong because it unnecessarily opens up possibilities to MANY bugs. When the @Override is invoked, the state of the object may be inconsistent and/or incomplete. A quote from Effective Java 2nd Edition, Item 17: Design and document for inheritance, or else prohibit it: There are … Read more

What issues should be considered when overriding equals and hashCode in Java?

The theory (for the language lawyers and the mathematically inclined): equals() (javadoc) must define an equivalence relation (it must be reflexive, symmetric, and transitive). In addition, it must be consistent (if the objects are not modified, then it must keep returning the same value). Furthermore, o.equals(null) must always return false. hashCode() (javadoc) must also be … Read more