Modifying setter generation? [message #205428] |
Wed, 01 June 2005 15:11  |
Eclipse User |
|
|
|
I'd like to add the keyword "final" before the argument in the setter
signature. Is there any way to modify the template to do this?
I see you can check off "final" but that's for the whole method. I want it
to look like this:
public void setFoo(final int foo) {
...
}
Otherwise, CheckStyle warns about the variable needing to be final.
Thanks,
Sean LeBlanc
|
|
|
|
|
|
|
|
Re: Modifying setter generation? [message #206861 is a reply to message #205613] |
Thu, 16 June 2005 10:55  |
Eclipse User |
|
|
|
"Eric Rizzo" <eclipse@rizzoweb.com> wrote in message
news:d7nhpj$beo$1@news.eclipse.org...
> Sean LeBlanc wrote:
>> I'd like to add the keyword "final" before the argument in the setter
>> signature. Is there any way to modify the template to do this?
>>
>> I see you can check off "final" but that's for the whole method. I want
>> it to look like this:
>>
>> public void setFoo(final int foo) {
>> ...
>> }
>>
>> Otherwise, CheckStyle warns about the variable needing to be final.
>
> Does it really? That is simply not true. There is no inherent *need* for
> setter arguments to be final. In fact, the only reason I know of to make a
> method parameter final is when it is used in the code of a local inner
> class.
> Seems to me CheckStyle is being too stringent in this case.
>
> Eric
As Tobias points out, CheckStyle can be configured to ignore this.
However, I like to have this check left on. This is something that is
recommended in _Hardcore Java_, as well, and I think in many cases it makes
sense as a guard against unintended consequences.
|
|
|
Powered by
FUDForum. Page generated in 0.10865 seconds