This question is not about how long should be correctly added to the int , but rather what happens when we cast it to the int incorrectly.
So, consider this code -
@Test public void longTest() { long longNumber = Long.MAX_VALUE; int intNumber = (int)longNumber;
This gives the result -
longNumber = 9223372036854775807 intNumber = -1
Now suppose I make the following change -
long longNumber = Long.MAX_VALUE - 50;
Then I get the output -
longNumber = 9223372036854775757 intNumber = -51
The question is , how is a long value that converts to int?
java casting
CodeBlue Sep 19 '12 at 19:12 2012-09-19 19:12
source share