This is due to integer overflow. When thisVal
is very large and anotherVal
is negative then subtracting the latter from the former yields a result that is bigger than thisVal
which may overflow to the negative range.
More Related Contents:
- How does Java handle integer underflows and overflows and how would you check for it?
- Why is 128==128 false but 127==127 is true when comparing Integer wrappers in Java?
- Why do == comparisons with Integer.valueOf(String) give different results for 127 and 128?
- why Integer.MAX_VALUE + 1 == Integer.MIN_VALUE?
- How can I detect integer overflow on 32 bits int?
- Why does Java think that the product of all numbers from 10 to 99 is 0?
- Declaring variables inside or outside of a loop
- Way to get number of digits in an int?
- Java integer to byte array
- How to handle very large numbers in Java without using java.math.BigInteger
- Why doesn’t Java throw an Exception when dividing by 0.0?
- Converting a string to an integer on Android
- Java local vs instance variable access speed
- The range of int in Java
- Java Embedded Databases Comparison [closed]
- What optimizations can I expect from Dalvik and the Android toolchain?
- Why is == true for some Integer objects? [duplicate]
- What to do with Java BigDecimal performance?
- Comparing chars in Java
- Loading a map using Properties class
- 09 is not recognized where as 9 is recognized [duplicate]
- java.lang.IllegalArgumentException: Comparison method violates its general contract [duplicate]
- Is there a default type for numbers in Java
- Java split String performances
- (obj == null) vs (null == obj)?
- Is it faster to access final local variables than class variables in Java?
- Why are Integers immutable in Java?
- Why proguard processes AndroidManifest.xml
- Is 00 an integer or octal in Java?
- Using int vs Integer