Is there any in-built contract checking in Java e.g. for the contract between a hashcode and the equals function?
For this question, let's stick with the hashcode/equals contract as an example, but I'm interested in contract checking in general. I have read in multiple places that equals and hashcode must satisfy a "contract" in Java:
- Equals must follow the three rules of an equivalence relation and also must be consistent on repeated calls
- Equal objects implies equal hashcodes
I understand the conditions, and they make sense to me. However, I'm wondering, is this just a contract that's written down on paper- essentially a strong guideline for developers to not write buggy code- or is it something that will be caught by Java as either a compile time or run time exception?