Does the Java 'final' keyword actually improve security?

前端 未结 12 866
遥遥无期
遥遥无期 2021-01-07 19:07

While there are many reasons to use the \'final\' keyword in Java, one of the ones I keep hearing over and over again is that it makes your code more secure. While this seem

12条回答
  •  無奈伤痛
    2021-01-07 19:26

    Final keyword is usually used to preserve immutability. To use final for classes or methods is to prevent linkages between methods from being broken. For example, suppose the implementation of some method of class X assumes that method M will behave in a certain way. Declaring X or M as final will prevent derived classes from redefining M in such a way as to cause X to behave incorrectly. It secures objects and methods from getting manipulated. But as for cryptography purpose, using final keyword is not the solution

提交回复
热议问题