Re: Why variables that we don't modify should be final?

Adam Sroka <[email protected]> Tue, 25 May 2010 15:52:05 -0700
Newsgroups gmane.comp.programming.refactoring
Message-ID <[email protected]>
It's a matter of much debate and religiosity. Personally, I only use the
final keyword for constant fields (e.g. static final CONSTANT) because that
is idiomatic in Java. I also, occasionally, use final for private fields
that are set at construction time to denote immutability.

There aren't really any performance advantages to final in a modern JVM. The
main advantage cited is the ability to prevent programmer mistakes or abuse.


On Tue, May 25, 2010 at 12:56 PM, Alberto Ivo <[email protected]> wrote:

>
>
> Hello,
>
> I just passed PMD in my Java code.. and a lot of variables the PMD says
> that
> should be final.. just because I do not modify.
> I know that, like this, it's safer because I'm sure that it wil be not
> modified ever...
> But, besides that, is there another advantage? like performance or anything
> else?
>
> Thanks in advance.
> Ivo
>
> [Non-text portions of this message have been removed]
>
>  
>


[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/refactoring/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/refactoring/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/