liveBook · Manning

Equality by value

Also called equals method, value equality

Equality by value is an equality semantics in which values are considered equal when they represent equivalent contents, regardless of object identity.

How 3 Manning books explain it

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.

Read how Kotlin in Action, 2E explains equality by value →

Also covered in

What to know first

Related concepts

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.