hash code
An int that an object computes from its contents so hash-based collections such as HashMap can find it quickly.
In more detail
Objects that are equal must return the same hash code, otherwise they get lost in hash-based sets and maps. Records generate a hashCode consistent with their equals, which makes them safe map keys when their components are.
Related terms
- equals method — The method that decides whether two objects hold the same value, as opposed to == which checks whether they are the same object.
- record (Java) — A compact Java class for plain data, declared with its components in one line, for which the compiler generates the fields, accessors, equals, hashCode and toString.
- Java Map — The collection interface that associates each unique key with one value, replacing the old value when a key is stored again.
Taught in
- Records And Data Classes — Modern Java: Virtual Threads & High-Throughput Services
- Classes, Records And Initialisation Order — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Inheritance, Overriding And Object's Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep