Equality by value
Equality by value is an equality semantics in which values are considered equal when they represent equivalent contents, regardless of object identity.
100 Java Mistakes and How to Avoid Them
The equals method is the Object method conventionally overridden to determine logical equality between objects.
- How it is used
- Distinguishes logical object comparison from reference identity before objects enter algorithms and collections.
- How deep it goes
- Explains call-site traps, type-specific alternatives, implementation mistakes, and hashCode consistency rather than deriving the full equality contract.
- Examples
- Uses cached Integer values, atomic variables, accidental unrelated arguments, faulty field comparisons, and mutated collection keys.
- What you can do after
- Diagnose/debug with it by choosing appropriate value comparisons and spotting equality failures in collection behavior.
Read how 100 Java Mistakes and How to Avoid Them explains equality by value →
Java Persistence with Spring Data and Hibernate epub
The equals method is the Java object method that determines whether one object should be considered equal to another.
- How it is used
- Distinguishes value equality from object and database identity when working with persistent components and detached entities.
- How deep it goes
- Implements equals() and hashCode() for components and entities, and explains generated-identifier hazards across persistence states.
- Examples
- Uses duplicate images in a set and users compared by username across persistence contexts.
- What you can do after
- Apply equality by value by implementing consistent equals() and hashCode() methods for embeddables and entities.
Read how Java Persistence with Spring Data and Hibernate epub explains equality by value →
Kotlin in Action, 2E
equals is an object method that determines whether another value is equal to the receiver according to the object's equality contract.
- How it is used
- Compares Kotlin objects by their stored values through `==` and supports reliable use in hash-based containers.
- How deep it goes
- Explains manual `equals`, null handling, identity checks, `hashCode` consistency, and generated data-class equality; omits a complete manual hash-code implementation.
- Examples
- Uses `Customer` and `Point` instances, including equal field values, null comparison, a hash-set lookup, and a data-class declaration.
- What you can do after
- Apply it by choosing `==` for value comparison, `===` for identity, and data classes or matched `equals` and `hashCode` for value objects.
Also covered in
- Clean Applications with Hexagonal ArchitectureIn early access (MEAP)
- Fabulous Adventures in Data Structures and Algorithms
What to know first
- MapA map is an associative data structure that stores key-value associations and supports retrieving values by key.
- hashsetA hash set is a collection of distinct values that uses hashing to support efficient membership testing without associated values.
- recordA record is a structured representation of related fields or components, either as one data entry or as a type defining such entries.
Related concepts
- hashsetused by · A hash set is a collection of distinct values that uses hashing to support efficient membership testing without associated values.
- dataclassproduced by · A data class is a class form for declaring structured data whose common data-oriented members can be generated from its declared fields or properties.
- operatorused by · An operator is a symbol, keyword, or language construct that specifies an operation on one or more operands.
- ..< operatorused by · The `..<` operator constructs a range that includes its lower endpoint and excludes its upper endpoint.
- anypart of · An any or some operation returns a Boolean indicating whether at least one element in a collection satisfies a predicate or, when none is supplied, is truthy.
- reference equalitycontrasts with · Reference equality is equality determined by whether two references designate the same object or instance rather than equivalent values or contents.
Questions about equality by value
What is equality by value?
Equality by value is an equality semantics in which values are considered equal when they represent equivalent contents, regardless of object identity.
Which Manning books explain equality by value?
100 Java Mistakes and How to Avoid Them, Java Persistence with Spring Data and Hibernate epub and Kotlin in Action, 2E.
What should I know before learning equality by value?
Manning books that teach equality by value usually introduce Java, Map, hashset and record first.
What is the difference between equality by value and reference equality?
Equality by value is an equality semantics in which values are considered equal when they represent equivalent contents, regardless of object identity. Reference equality is equality determined by whether two references designate the same object or instance rather than equivalent values or contents.
What is equality by value part of?
Equality by value is part of any. An any or some operation returns a Boolean indicating whether at least one element in a collection satisfies a predicate or, when none is supplied, is truthy.
What is equality by value also called?
Equality by value is also called equals method or value equality.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


