On 20 December 2015 at 10:52, Felix Schumacher
<[email protected]> wrote:
> Am 13.12.2015 um 14:11 schrieb Philippe Mouawad:
>>
>> Hi Felix,
>> Do you have an example where it does not seem justified ?
>
> I wondered why they were (and sometimes were not) used.
>
> I stumbled upon the usage (or non usage) of final when looking at a findbugs
> report on CsvSampleWriter. That class uses a overridable method setWriter
> from its constructor, which findbugs finds "scary".
>
> In other classes I found a few methods declared final and other not, without
> a documentation, why those final classes are closed for further inheritance
> and the others not.
>
> I haven't looked, whether they were justified or not, I was just curious.

Final is required in some cases, e.g. methods called from constructor
(*) or parameter passed to nested class.

It is also potentially useful as a way of documenting that an item is
not intended to be altered (although of course that doesn't stop a
mutable object from being changed). This can be helpful when trying to
follow code.

Some people like to make everything possible final; I think that can
be distracting.

(*) if a sub-class overrides the method, it may be called before the
class has been fully constructed so may fail in unexpected ways.

> Regards,
>  Felix
>
>>
>> Thanks
>>
>> On Sunday, December 13, 2015, Felix Schumacher <
>> [email protected]> wrote:
>>
>>> Hi all,
>>>
>>> I see a lot of methods in the newly added report package, that are
>>> declared final.
>>>
>>> What is the reasoning behind this?
>>>
>>> Regards,
>>>   Felix
>>>
>>
>

Reply via email to