Does the Java 'final' keyword actually improve security?

前端 未结 12 909
遥遥无期
遥遥无期 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:21

    Secure against what?

    In terms of mobile code (code that can move between systems - applets, midlets, WebStart, RMI/JINI, etc), it is very important. Applied to classes, and to a lesser extent accessible methods, it prevents malicious implementations. Similarly with accessible fields, notable statics. If you are going to write code that may become part of a library, you need to be keenly aware of this.

    For typical, say, web or desktop app code, it is far less important. However, its absence on fields makes code more difficult to read and indicates a confused programmer. Such code is unlikely to be secure just because it is badly written.

提交回复
热议问题