Skip to content

Integer comparison by == #91

Description

@cushon

Original issue created by antrim@google.com on 2013-02-22 at 07:27 PM


Integer a = 1000;
Integer b = 1000;

if (a == b) // Results in false.

In Java autoboxing to Char, Short, Integer and Long returns an object from the pool when the autoboxed value is between -128 and 127 (inclusive), and it creates new object every time for other values, so reference check fails.

With that, code would usually pass all unit tests (that generally have simple and small values), but fail in prod environment.

int to Integer and int to int comparison works as expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions