Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Although this change has no effect on compilation, the programmer's intent is clearer.

Noncompliant Example

In this noncompliant example, a A programmer or code reviewer might mistakenly believe that both i and j are initialized to 1 while reviewing this noncompliant code example. In fact, only j is initialized, while i remains uninitialized.

...

Code Block
bgColor#FFcccc
public class ExampleExample<T> {
  private T a, b, c[], d;

  public Example(T in){
    a = in;
    b = in;
    c = (T[]) new Object[10];
    d = in;
  }
}

...

Code Block
bgColor#ccccFF
public class Example {
  private T a;
  private T b;
  private T[] c;
  private T d;

  public Example(T in){
    a = in;
    b = in;
    c = (T[]) new Object[10];
    d = in;
  }
}

Exceptions

DCL04-01: Note that the declaration of a loop counter in a for statement is in violation of this recommendation because the declaration is not on its own line with an explanatory comment about the role of the variable. However, the intent of the loop counter is clear enough from the context in which it is declared to typically not require a comment about the role of the variable.

DCL04-01: Trivial declarations for loop counters can reasonably be included within a for statement:

...