Use final

October 27, 2009 by · 2 Comments 

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.

About Frank Salinas
Frank is a senior level Java developer working for a privately owned company based in San Francisco, California. He has over 12 years of experience developing software on Microsoft and Linux/Java/JEE platforms and specializes in SaaS, eDiscovery and Document Review platforms.

Comments

2 Responses to “Use final”
  1. Peter Lawrey says:

    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:

    @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.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!