seetharaman venkatasamy wrote:
Matthew Cox wrote:There are drawbacks to marking anything as final method or variable.
What are all the drawbacks?
variables and methods marked as final have the drawback of the following:
1. Scale of use - Items that utilize final are more commonly data structures or prohibitive supertypes as they cannot be modified (method or object) and can only be assigned a value or implementation (respectively) once.
2. Flexibility - Future builds of your code could have dependencies upon objects, variables, and methods that are marked as final, but conflict with newer code requirements.
3. Incompatibility with Inheritance (as in the item cannot be extended or enhanced in any form)
-Although, I do understand and admit that in most cases, the use of
final would be just for this purpose, to prevent modification
I want to make a clear statement though. I only mentioned the "drawbacks" in relation to the possibility of using
final haphazardly. If this modifier is used correctly, then drawbacks will not be an issue. But simply using this modifier to restrict access without regards to future modification or needs would be careless at best.
Since the question was semi-vague to begin with (no offense meant to the original poster), I merely wanted to give warning if this was the case for him.
P.s
I bet there are more, but since I possess only so much knowledge =P that is all I can list for now.