Jtest logo




Contents  Previous  Next  Index

MISC.HMF


Avoid hiding member fields in member methods

Description

This rule flags code where a member fields is hidden in a member method.

Variables declared local to a "class" method can hide instance fields of the same name, effectively blocking access to the field.

Local variables with the same name as instance fields can make your code difficult to read. It is good practice to make a variable's name as unique as possible for coding clarity

Example

 package MISC;
 
 abstract class HMF {
     public int method2 () {
         int i = 5;       // violation
         System.out.println (i);
     }
 
     private int i = 0;
 }

Repair

Give the local variable a unique name.


Contents  Previous  Next  Index

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