'final' variables

Tyler Knott tywebmail at mailcity.com
Tue Mar 20 08:10:43 PDT 2007


Lionello Lunesu Wrote:
> What's the use of "final" for variables? I'm saying "for variables" 
> because for methods the benefit is only too clear.
> 

Because the "const" keyword is being repurposed for read-only references to mutable or non-mutable data, we need a new keyword for non-mutable variables.  "final" fills that purpose nicely.  If the value of the variable is known at compile time, the compiler can constant-fold away the memory access to that variable for a small speed boost.  If the value is only determinable at runtime, that can still allow the compiler to make some optimizations that would not be possible with mutable variables.



More information about the Digitalmars-d mailing list