-
-
Couldn't load subscription status.
- Fork 382
Variables
Raycoms edited this page Jan 9, 2019
·
5 revisions
- Named in
lowerCamelCaseconvention.
- Declare variables close to the location where they are used within Methods.
- Fields are declared at the beginning of each class over the constructor.
- Fields my references via
thisoperator
/**/
public class MyClass
{
private final int initial = 0;
/**/
public void someMethod( )
{
final int initial = this.initial;
// Other method content
}
/**/
}
/**/- If you get some
getXY()method to store a reference to anObject, centralize thevariable
/**/
public void someMethod( )
{
final Object object = this.other.getObject();
if ( checkCondition( ) )
{
object.someMethod( );
}
else {
object.otherMethod( );
}
}
/**/- Declare
once instanciatedvariables asfinal.
/**/
public void someMethod( )
{
final String neverChanged = "foobar";
// Other method content
}
/**/