Fields Replacing Local Variables Examples
.
Summary Fields can be used in place of local variables as a work around to the Local Variable Limitations

Object fields do not have the same limitations as local variables and can be used in place of local variables as a work-around

Caution needs to be used with fields also though as

  • Fields are not thread safe - This is not an issue with the current implementations but when threads are introduced shortly accessing fields can cause conflict. This section will be upated when user defined threads are introduced
  • Field access is substantially slower than local variable access.
 //All the local variable slots are used in the parameters
 int total; //Declare total as a field by putting outside the method
 int foo( int x1, int x2, int y1, int y2, int width, int height ){


        total = a + b + c + d + e + f;


        return total / ( width + height );
 }