Java Reference
In-Depth Information
Compliant Solution (Different Types)
This compliant solution places each declaration on its own line and uses the preferred
notation for array declaration:
Click here to view code image
public class Example<T> {
private T a; // Purpose of a...
private T b; // Purpose of b...
private T[] c; // Purpose of c[]...
private T d; // Purpose of d...
public Example(T in){
a = in;
b = in;
c = (T[]) new Object[10];
d = in;
}
}
Applicability
Declarationofmultiplevariablesperlinecanreducecodereadabilityandleadtoprogram-
mer confusion.
When more than one variable is declared in a single declaration, ensure that both the
type and the initial value of each variable are self-evident.
Declarationsofloopindicesshouldbeincludedwithina for statement,evenwhenthis
results in variable declarations that lack a comment about the purpose of the variable:
Click here to view code image
public class Example {
void function() {
int mx = 100; // Some max value
for (int i = 0; i < mx; ++i ) {
/* ... */
}
}
}
Search WWH ::




Custom Search