Re: effects of "final" in parameters



Chris Uppal wrote:
tom fredriksen wrote:


- how often is "final" actually used in code to make parameters
immutable?


Note that it doesn't make the referred-to object immutable, it just means that
you can't assign another object ref to the parameter variable.

Some people seem to use it a lot. I consider it pointless myself. (Unless, of
course, I /have/ to use it to satisfy the compiler that an inner class won't
break if it refers to the parameter). If I don't want to change the value of a
parameter then I don't change it -- adding decoration to tell the compiler that
I don't intend to change it, so that it can then check that I don't change it,
seems a singularly unproductive exercise.



The voice of reason - thank you Chris!

The amount of times I've tried explaining this to others...... (walks away shaking his head...)
.



Relevant Pages

  • Re: effects of "final" in parameters
    ... you can't assign another object ref to the parameter variable. ... parameter then I don't change it -- adding decoration to tell the compiler ... I don't intend to change it, so that it can then check that I don't change ... Most methods will not assign to their formal parameters. ...
    (comp.lang.java.programmer)
  • Re: effects of "final" in parameters
    ... you can't assign another object ref to the parameter variable. ... I /have/ to use it to satisfy the compiler that an inner class won't ... I don't intend to change it, so that it can then check that I don't change it, ... are sometimes touted as an optimisation (which I doubt, ...
    (comp.lang.java.programmer)
  • Re: Why does this compile?
    ... >> Becsaue a return type mismatch causes a type error, ... > I agree that the compiler should catch those return errors, however, I ... > fail to understand why ignoring the return type of a function is such ... so a programmer might indeed intend to omit a ...
    (comp.lang.cpp)
  • Re: How to use SHGetFolderPath()?
    ... I don't intend to continue this thread anyway. ... I said that the Microsoft compiler includes non-standard extensions ... > releases old and released before the C++ standard was released means that ...
    (microsoft.public.vc.mfc)
  • Re: NEWBIE QUESTION: "Warning: Extension: REAL array index at (1)" - please help
    ... but the compiler accepts it anyway. ... variable as a loop index. ... You aren't printing ... that is assuming that you intend ...
    (comp.lang.fortran)