Jtest logo




Contents  Previous  Next  Index

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);
    }
 }
 

Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft