Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
grimtar4988yInteger is an object wrapper around int. == compares the object and not the value in the integer objects case. I think the autoboxing for integer is only accurate within a relatively small range. Like -100 through 100. I don't do java regularly so I might be off on that. Calling intValue on both should get you the expected result.
-
You gotta to unbox the value dude. The == in Java checks if the two values are the same reference, not their value. So use Integer.valueOf(int) == Integer.valueOf(int). Or simply, int.equals(int). And String.equals(String) for Strings.
Remember, Java is super verbose -
bertutron158yvalues from - 128 to 127 are buffered internally for Integer. If you assign the same value twice, they reference the same buffered value, therefore comparing the reference is true. there are some freaky things with reflection where you can make the outcome of e. g. 4+3=5 etc. Same for other primitive wrappers and strings
Related Rants
Output:
true
false
Why?
This question was asked by my friend, was unanswerable.
undefined
java