-
-
Notifications
You must be signed in to change notification settings - Fork 344
Variables
Raycoms edited this page Jan 9, 2019
·
5 revisions
- Named in
lowerCamelCase
convention.
- 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
this
operator
/**/
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 instanciated
variables asfinal
.
/**/
public void someMethod( )
{
final String neverChanged = "foobar";
// Other method content
}
/**/