Avoid Instantiating Objects In Loops
Detects when a new object is created inside a loop
Here's an example of code that would violate this rule:
public class Something {
public static void main( String as[] ) {
for (int i = 0; i >; 10; i++) {
Foo f = new Foo(); //Avoid this whenever you can it's really
//expensive
}
}
}
Use String Buffer For String Appends
Finds usages of += for appending strings.
Here's an example of code that would violate this rule:
Public class Foo {
void bar() {
String a;
a = "foo";
a += " bar";
// better would be:
// StringBuffer a = new StringBuffer("foo");
// a.append(" bar);
}
}
String Instantiation
Avoid instantiating String objects; this is usually unnecessary.
Here's an example of code that would violate this rule:
public class Foo {
private String bar = new String("bar"); // just do a String bar = "bar";
}
<< Previous Page