equals() and hashCode() Contract
Learn equals() and hashCode() Contract (Advanced Java Concepts, Java) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
1. Introduction Equals defines logical equality and hashCode returns an int used by hash collections . They must be consistent: equal objects have equal hash codes .
More lessons in Advanced Java Concepts
- Enums in Java
- Generics in Java
- Annotations in Java
- Reflection API
- Nested & Inner Classes
- Interfaces in Java
- Comparable vs Comparator
- Object Cloning
- try-with-resources
- Varargs in Java
- Instance and Static Initializer Blocks
- Custom Exceptions in Java
- Marker Interfaces in Java
- The Object Class in Java
- String Formatting in Java
- Immutable Classes in Java
- Multi-catch Block and the try-finally Return Trap