Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An unexpected issue that new Integer(128) == new Integer(128) is false #123

Open
FredWe opened this issue Feb 25, 2017 · 0 comments
Open

Comments

@FredWe
Copy link
Owner

FredWe commented Feb 25, 2017

System.out.println(new Integer(128) == new Integer(128)); prints false
but System.out.println(new Integer(127) == new Integer(127)); prints true

Explanation: http://stackoverflow.com/questions/1700081/why-does-128-128-return-false-but-127-127-return-true-when-converting-to-integ

The obvious conclusion: never rely on two references being identical, always compare them with .equals() method.

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

No branches or pull requests

1 participant