This content has been marked as final.
Show 5 replies
-
1. Re: Why are you using final for argument's declaration
juhalindfors Apr 17, 2003 3:03 PM (in response to naxius)"Juha Lindfors" wrote:
The argument name very often shadows a field name in the same class. Declaring the argument as final prevents you from accidentally assigning a value to the local arg reference when you wanted to assign to instance field reference.
It is not really an optimization, it is used as a defensive programming technique. Personally I don't like it and don't use it. Others obviously feel differently :-) -
2. Re: Why are you using final for argument's declaration
naxius Apr 18, 2003 3:17 AM (in response to naxius)"naxius" wrote:
If declaring arguments as final is to prevent an accidentally assignment, there is another technique to do that :
public void setXxx(int xxx) {
this.xxx = xxx;
}
And that's it.
I thought that the compiler was doing some optimization stuff ?
Thank you.
Alexandre -
3. Re: Why are you using final for argument's declaration
juhalindfors Apr 18, 2003 4:16 AM (in response to naxius)"Juha Lindfors" wrote:
Yes the point is that it is easy to forget the 'this' reference. -
4. Re: Why are you using final for argument's declaration
hezekiel May 9, 2003 8:20 AM (in response to naxius)"Hezekiel" wrote:
Not if you use a decent editor (aka IntelliJ). It will highlight the questionable assignment (prints it with light grey) so it definately strikes out of the context.
It also highlights all the unused variables and import statements similarly. It's funny how much trash you see in the sources of others when you open those with IntelliJ...
Even the sources for java itself are cluttered with unused imports and variables ;-)
Before commit to cvs:
1. Hit CTRL+ALT+L (apply coding style)
2. Hit CTRL+ALT+O (optimize imports)
3. see that the source file is marked with green (no stupid assigments / no unused variables / valid javadoc)
4. Right click on editor -> choose commit
5. Write revision notes -> click ok.
I can't stand people who use notepad to write java code!! =) -
5. Re: Why are you using final for argument's declaration
juhalindfors May 9, 2003 10:04 AM (in response to naxius)"Juha Lindfors" wrote:
> Not if you use a decent editor (aka IntelliJ).
It is not easy to forget even if you use notepad (I do) but some people are not so easily convinced.