~/talk

Comparison Method Violates Its General Contract! (Part 2)

Talkat Devoxx Belgium 2017 · 2017-11-06..11-10· [java]
slides:none on file

Explains why a buggy Comparator triggers "comparison method violates its general contract": TimSort used by Java 7+ detects inconsistent ordering, so incorrect logic can throw an exception or silently produce wrong order. Shows Java 8 combinators used to build correct comparators (comparingInt/comparingDouble, thenComparing, nullsFirst/nullsLast), demonstrates BigDecimal’s compareTo inconsistent with equals causing TreeSet vs HashSet surprises, and warns against setting java.util.Arrays.useLegacyMergeSort because it hides bugs rather than fixing them.

AI-written summary · about

  1. 0:00Start
  2. 0:18Combinator Methods on the Comparator Interface
  3. 1:16Combinator Methods
  4. 2:44Demo
  5. 6:39Comparing Int
  6. 8:26Nullpointerexception
  7. 16:27The Illegal Argument Exception
  8. 16:42Java Util Arrays Use Legacy Merge Sort
  9. 19:09A Downstream Comparator
  10. 24:12Numeric Consistency Properties
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.