Java Reference
In-Depth Information
int bow;
// Position near the front of the boat
/* ... */
int stern; // Position near the back of the boat
Noncompliant Code Example
Thisnoncompliantcodeexampleprintstheresultofaddingan int anda long value,even
though it may appear that two integers ( 11111) are being added:
Click here to view code image
public class Visual {
public static void main(String[] args) {
System.out.println(11111 + 1111l);
}
}
Compliant Solution
Thiscompliantsolutionusesanuppercase L ( long )insteadoflowercase l todisambiguate
the visual appearance of the second integer. Its behavior is the same as that of the non-
compliant code example, but the programmer's intent is clear:
Click here to view code image
public class Visual {
public static void main(String[] args) {
System.out.println(11111 + 1111L);
}
}
Noncompliant Code Example
This noncompliant code example mixes decimal values and octal values while storing
them in an array:
Click here to view code image
int[] array = new int[3];
void exampleFunction() {
array[0] = 2719;
Search WWH ::




Custom Search