Skip to content

Compare boxed values by value in Java - #851

Merged
mristin merged 1 commit into
mainfrom
mristin/fix-java-boxed-equality
Oct 15, 2026
Merged

mristin merged 1 commit into
mainfrom
mristin/fix-java-boxed-equality

Conversation

@mristin

@mristin mristin commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

We represent the integers, the floats and the booleans as Long's, Double's and Boolean's in the arguments, the properties and the collections, so == and != compared the references of two such values. This worked only by chance for the Long's between -128 and 127, which Java caches, and practically never for the Double's.

We now unbox the left operand, e.g.,
(long) child.getAOnly() == childCopy.getAOnly(), unless an operand is a literal, an arithmetic result or a length, which are primitives already.

We represent the integers, the floats and the booleans as ``Long``'s,
``Double``'s and ``Boolean``'s in the arguments, the properties and
the collections, so ``==`` and ``!=`` compared the references of two
such values. This worked only by chance for the ``Long``'s between -128
and 127, which Java caches, and practically never for the ``Double``'s.

We now unbox the left operand, *e.g.*,
``(long) child.getAOnly() == childCopy.getAOnly()``, unless an operand
is a literal, an arithmetic result or a length, which are primitives
already.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 38802716091

Coverage at 90.149% (no base build to compare)

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 12 of 12 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 50645
Covered Lines: 45656
Line Coverage: 90.15%
Coverage Strength: 2.7 hits per line

💛 - Coveralls

@mristin
mristin merged commit 406b77d into main Oct 15, 2026
5 checks passed
@mristin
mristin deleted the mristin/fix-java-boxed-equality branch October 15, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants