~/talk

Comparison Method Violates Its General Contract! (Part 1)

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

Explains why Java sorting sometimes throws "comparison method violates its general contract!" by showing concrete buggy comparators: Integer overflow via subtraction causes wrong signs, boxed Integers accidentally use reference equality instead of value equality, and IEEE floating point produces NaN compares false to everything so naive <, ==, > logic returns equals. Uses a logging wrapper comparator to replay comparisons, and recommends Integer.compare / Double.compare or natural order to get correct, predictable sorting.

AI-written summary · about

  1. 0:00Introduction
  2. 0:43Title
  3. 3:13Integers
  4. 5:40Comparator
  5. 7:14Illegal argument exception
  6. 8:02Demo
  7. 8:16Run
  8. 8:40Writing a comparator
  9. 9:33The problem
  10. 10:30Wrapper comparator
  11. 13:05Relational comparator example
  12. 14:23Logging comparator example
  13. 18:36Checking the results
  14. 23:38Recap
  15. 26:03Comparator vs Comparable
~/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.