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 Java object equality from instance identity and database row identity when mapping persistent objects.
- How deep it goes
- Works through equality overrides, detached-instance behavior, and generated-identifier hash instability; limits the need for entity overrides to detached comparisons.
- Examples
- Tests duplicate images in a `Set` and users loaded through separate persistence contexts.
- What you can do after
- Build it from scratch by implementing consistent `equals()` and `hashCode()` methods for value components and entities requiring detached equality.
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.
Related concepts
- hashsetused by · A hash set is a collection of distinct values that uses hashing to support efficient membership testing without associated values.
- 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.
- dataclassproduced by · A data class is a class construct for declaring data-bearing types, often with standard data-oriented methods generated from their declared fields or properties.
- ..< operatorused by · The `..<` operator constructs a range that includes its lower endpoint and excludes its upper endpoint.
- operatorused by · An operator is a symbol, keyword, or language construct that specifies an operation on one or more operands.
- reference equalitycontrasts with · Reference equality is equality determined by whether two references designate the same object or instance rather than equivalent values or contents.
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.


