Skip to content

Variables

Isfirs edited this page Aug 23, 2016 · 5 revisions

Naming

  • Named in lowerCamelCase convention.

Usage

  • Declare variables close to the location where they are used.
  • Fields my references via this operator
/**/
public class MyClass
{
    private final int initial = 0;

    /**/

    public void someMethod( )
    {
        final int initial = this.initial;
        // Other method content
    }

    /**/
}
/**/

Receiving variables

  • If you get some getXY() method to store a reference to an Object, centralize the variable
/**/
public void someMethod( )
{
    final Object object = this.other.getObject();

    if ( checkCondition( ) )
    {
        object.someMethod( );
    }
    else {
        object.otherMethod( );
    }
}
/**/

Flags

  • Declare once instanciated variables as final.
/**/
public void someMethod( )
{
    final String neverChanged = "foobar";
    // Other method content
}
/**/