Use final

Tuesday, October 27, 2009 21:19
Posted in category Java

The final keyword is one that I find is under utilized. Use final in your projects as a means of defensive programming. If you are unfamiliar with this keyword here is a great article on its usage.

Renaud Waldura’s The Final Word On the final Keyword .

No related posts.

You can leave a response, or trackback from your own site.

2 Responses to “Use final”

  1. Peter Lawrey says:

    November 7th, 2009 at 1:47 am

    Its so under utilised, its a shame that final wasn’t the default and a keyword like ‘var’ wasn’t used for mutable variables/fields.

    I suggest you make all fields final if possible. While performance is a consideration, I believe it makes it much clearer which fields can be changed over the life of an object.

  2. Frank says:

    November 8th, 2009 at 9:10 am

    @Peter – I agree. If developers could just forget about the potential performance optimizations final may, or may not, provide and focus on the intended purpose of the keyword for preserving immutability code quality would increase. In my opinion, code quality comes before performance and leveraging defensive programming techniques such as enforcing immutabilty appropriately increases code quality.

Leave a Reply