GC.AUTP
Avoid unnecessary temporaries when converting primitive types to String
Description
This rule flags code where an unnecessary temporary is used when converting primitive types to String.
Java provides wrapping classes for the primitive types. Those classes provide a static method `toString (...)' to convert the primitive type into their String equivalent. Use this method instead of creating an object of the wrapping class and then using the instance `toString ()' method.
Example
package GC;
public class AUTP {
String foobar (int x) {
return new Integer (x).toString (); // Violation
}
}
Repair
class AUTP_fixed {
String foobar (int x) {
return Integer.toString (x);
}
}
|