“最终”怎么样?在安全方面发挥作用? [英] How does "final" play a role in security?

查看:80
本文介绍了“最终”怎么样?在安全方面发挥作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在维基百科中读到:


最终类不能被子类化。这是出于
安全性和效率的原因。

A final class cannot be subclassed. This is done for reasons of security and efficiency.

我想知道<$ c $的安全性Java中的c> final 可以实现吗?

推荐答案

final 不提供任何安全保障。期待它是愚蠢的。它提供了一种安全性。

final does not provide any security whatsoever. It's silly to expect it to. It provides a kind of safety.

虽然你的问题与java有关,但我会指出Marshall Cline的C ++ FAQ回答类似的问题。

Though your question is related to java, I'll point you to Marshall Cline's C++ FAQ which answers a similar question.

http:// www.parashift.com/c++-faq/encap-is-not-security.html


[7.8]封装安全设备?

[7.8] Is Encapsulation a Security device?

否。

封装!=安全。

封装可以防止错误,而不是间谍。

Encapsulation prevents mistakes, not espionage.

让我添加像 public这样的关键字 private final 等不会阻止故意滥用。它们只是通过防止意外或无意滥用来帮助强制执行设计的构造。

Let me add that the keywords like public, private, final etc do not prevent intentional misuse. They are just constructs which help enforce design by preventing accidental or unintentional misuse.

想要替换基类中的功能的程序员可以使用其他方法来执行此操作 - 最简单的是根本不使用该类并自行完成。

A programmer who wants to substitute functionality in the base class can use other ways to do it - the simplest is it to not use the class at all and do his own stuff.

如果你想阻止访问或任何其他事情,请在底层操作系统中执行,而不是在你的班级图书馆。

If you want to prevent access or any other thing, do it in the underlying OS, not in your class library.

与往常一样,维基百科可能是一个很好的起点,但很少是权威的来源。

As always, Wikipedia may be a good starting point for something but is rarely the authoritative source.

这篇关于“最终”怎么样?在安全方面发挥作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆