liveBook · Manning

Comparable interface

Comparable is an interface, protocol, or mechanism that specifies whether values of a type can be compared or ordered.

How 3 Manning books explain it

100 Java Mistakes and How to Avoid Them

Comparable is a Java interface whose implementation defines a natural ordering for instances through compareTo.

How it is used
Defines natural ordering for Java objects and exposes comparison mistakes that can silently misorder data.
How deep it goes
Details sign-based compareTo rules and focused failures, while limiting collection internals to a collision-dependent HashSet case.
Examples
Uses boolean wrappers, a name-and-age User record, and mutable StringBuilder values stored in HashSet.
What you can do after
Diagnose/debug comparison code by checking signs, equality results, and unsafe mutable or inconsistent collection keys.

Read how 100 Java Mistakes and How to Avoid Them explains Comparable interface →

Clojure: The Essential Reference

The Java Comparable interface defines a natural ordering for instances of a class through its compareTo method.

How it is used
Supplies natural ordering to Clojure’s default comparison and sorting of compatible custom objects.
How deep it goes
Explains comparison results, compatibility requirements, exceptions, and a worked record implementation without detailing Java interface internals.
Examples
Uses distance-ordered point and gas-station records, plus sorted-map keys, to demonstrate ordering.
What you can do after
Build it from scratch by implementing `compareTo` on a Clojure record so its instances can be sorted.

Read how Clojure: The Essential Reference explains Comparable interface →

Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

Comparable is a Swift standard-library protocol for types whose values can be ordered relative to one another.

How it is used
Supports ranking search nodes so A* can prioritize candidates by combined cost and heuristic.
How deep it goes
Defines comparison for a concrete generic Node type but does not survey Comparable requirements beyond the shown operators.
Examples
Uses a generic Node whose < operator compares cost plus heuristic and whose == operator compares reference identity.
What you can do after
Apply it via Swift operator overloads to rank custom search nodes for priority-based algorithms.

Read how Classic Computer Science Problems in Swift: Essential techniques for practicing programmers explains Comparable interface →

Related concepts

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.