Skip to main content
added 1 character in body
Source Link
djna
  • 56.2k
  • 14
  • 80
  • 124

The final prevents you from assiningassigning a new value to the variable, and this can be helpful in catching typos. Stylistically you might like to keep the parameters received unchanged and assign only to local variables, so final would help to enforce that style.

Must admit I rarely remember to use final for parameters, maybe I should.

public int example(final int basicRate){ int discountRate; discountRate = basicRate - 10; // ... lots of code here if ( isGoldCustomer ) { basicRate--; // typo, we intended to say discountRate--, final catches this } // ... more code here return discountRate; } 

The final prevents you from assining a new value to the variable, and this can be helpful in catching typos. Stylistically you might like to keep the parameters received unchanged and assign only to local variables, so final would help to enforce that style.

Must admit I rarely remember to use final for parameters, maybe I should.

public int example(final int basicRate){ int discountRate; discountRate = basicRate - 10; // ... lots of code here if ( isGoldCustomer ) { basicRate--; // typo, we intended to say discountRate--, final catches this } // ... more code here return discountRate; } 

The final prevents you from assigning a new value to the variable, and this can be helpful in catching typos. Stylistically you might like to keep the parameters received unchanged and assign only to local variables, so final would help to enforce that style.

Must admit I rarely remember to use final for parameters, maybe I should.

public int example(final int basicRate){ int discountRate; discountRate = basicRate - 10; // ... lots of code here if ( isGoldCustomer ) { basicRate--; // typo, we intended to say discountRate--, final catches this } // ... more code here return discountRate; } 
added 290 characters in body
Source Link
djna
  • 56.2k
  • 14
  • 80
  • 124

The final prevents you from assining a new value to the variable, and this can be helpful in catching typos. Stylistically you might like to keep the parameters received unchanged and assign only to local variables, so final would help to enforce that style.

Must admit I rarely remember to use final for parameters, maybe I should.

public int example(final int basicRate){ int discountRate; discountRate = basicRate - 10; // ... lots of code here if ( isGoldCustomer ) { basicRate--; // typo, we intended to say discountRate--, final catches this } // ... more code here return discountRate; } 

The final prevents you from assining a new value to the variable, and this can be helpful in catching typos. Stylistically you might like to keep the parameters received unchanged and assign only to local variables, so final would help to enforce that style.

Must admit I rarely remember to use final for parameters, maybe I should.

The final prevents you from assining a new value to the variable, and this can be helpful in catching typos. Stylistically you might like to keep the parameters received unchanged and assign only to local variables, so final would help to enforce that style.

Must admit I rarely remember to use final for parameters, maybe I should.

public int example(final int basicRate){ int discountRate; discountRate = basicRate - 10; // ... lots of code here if ( isGoldCustomer ) { basicRate--; // typo, we intended to say discountRate--, final catches this } // ... more code here return discountRate; } 
Source Link
djna
  • 56.2k
  • 14
  • 80
  • 124

The final prevents you from assining a new value to the variable, and this can be helpful in catching typos. Stylistically you might like to keep the parameters received unchanged and assign only to local variables, so final would help to enforce that style.

Must admit I rarely remember to use final for parameters, maybe I should.