Java Reference
In-Depth Information
if (i == str.length()-1) {
/* This code is now executed */
}
}
return 0;
}
Noncompliant Code Example (Code with No Effect)
In this noncompliant code example, the comparison of
s
to
t
has no effect:
String s;
String t;
// ...
s.equals(t);
This error is probably the result of the programmer intending to do something with the
comparison, but failing to complete the code.
Compliant Solution
In this compliant solution, the result of the comparison is printed out:
String s;
String t;
// ...
if (s.equals(t)) {
System.out.println("Strings equal");
} else {
System.out.println("Strings unequal");
}
Noncompliant Code Example (Unused Values)
In this example,
p2
is assigned the value returned by
bar()
, but that value is never used: