...
According to the Java Language Specification, Section 4.2.1, "Integral Types and Values," the values of the integral types are integers in the inclusive ranges shown in the following table:
Type | Inclusive Range |
---|---|
| --128 to 127 |
| --32,768 to 32,767 |
| - -2,147,483,648 to 2,147,483,647 |
| - -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
| |
...
Operator | Overflow |
| Operator | Overflow |
| Operator | Overflow |
| Operator | Overflow |
---|---|---|---|---|---|---|---|---|---|---|
{ | yes |
| | yes |
| | no |
| | no |
| yes |
| | yes |
| | no |
| | no |
| yes |
| | yes |
| | no |
| | no |
| yes |
| | no |
| \ | no |
| | no |
| no |
| | no |
| { | no |
| | no |
| yes |
| | no |
| { | no |
| | no |
| yes |
| | no |
| | no |
| ||
| no |
| | no |
| un { | no |
| ||
| yes |
| | no |
| un | yes |
|
Wiki Markup |
---|
Failure to account for integer overflow has resulted in failures of real systems, for example, when implementing the {{compareTo()}} method. The meaning of the return value of the {{compareTo()}} method is defined only in terms of its sign and whether it is zero; the magnitude of the return value is irrelevant. Consequently, an apparent but incorrect optimization would be to subtract the operands and return the result. For operands of opposite signs, this can result in integer overflow, consequently violating the {{compareTo()}} contract \[[Bloch 2008, Item 12|AA. Bibliography#Bloch 08]\]. |
...