Java是否具有“私有保护”的功能?访问修饰符? [英] Does Java have a "private protected" access modifier?

查看:123
本文介绍了Java是否具有“私有保护”的功能?访问修饰符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到一些参考文献引用Java中的访问修饰符,称为 private protected (两个词加在一起):

I have seen some references refer to a access modifier in Java called private protected (both words together):

private protected someMethod() {

}

我发现与此有关的页面之一是此处。在我的学校课程中,还提到了此访问修饰符(并说它存在)。但是,使用它会导致Java语言出错。

One of the pages I found referring to this is here. My school lesson also referred to this access modifier (and said it exists). Using it, however, results in an error in the Java language.

我尝试使用变量和方法,但我很确定它不存在,但是我想要解释发生了什么。是否考虑过,然后拒绝了?还是在新版本的Java中将其删除?

I tried with both variables and methods and I'm pretty sure it doesn't exist, but I want an explanation of what happened. Was it considered, then rejected? Or did it get removed in a newer version of Java?

编辑:我不是在寻找受受保护

I am not looking for info about the protected keyword.

推荐答案

删除访问修饰符



Java做到了最初具有 private受保护的修饰符,但在JDK 1.0.2(第一个 stable 版本,我们今天知道的Java 1.0)中已将其删除。有关JDK 1.0.2的一些教程(此处,并此处)说: / p>

Removal of the access modifier

Java did originally have the private protected modifier, but it was removed in JDK 1.0.2 (the first stable version, the Java 1.0 we know today). A few tutorials regarding JDK 1.0.2 (here and here) say the following:


注意:Java语言的1.0版本支持五个访问级别:上面列出的四个级别加上私有保护。高于1.0的Java版本不支持受私有保护访问级别;您不应再在Java程序中使用它。

Note: The 1.0 release of the Java language supported five access levels: the four listed above plus private protected. The private protected access level is not supported in versions of Java higher than 1.0; you should no longer be using it in your Java programs.

另一个关于SoftwareEngineering.SE的答案指出:


Java最初具有这样的修饰符。它被编写为受私有保护,但在Java 1.0中已删除。

Java originally had such a modifier. It was written private protected but removed in Java 1.0.

现在查看 Java版本历史记录


JDK 1.0

第一版于 1996年1月23日发布,叫做橡树第一个稳定版本JDK 1.0.2被称为Java 1。

由此,我们可以总结有关1.0.2版的教程指的是第一个版本JDK 1.0,该语言称为Oak,但来自SoftwareEngineering.SE指的是第一个稳定版本JDK 1.0.2,名为Java 1.0,当时删除。

From this, we can conclude the tutorials regarding version 1.0.2 refer to the very first version, JDK 1.0, where the language was called Oak, but the one from SoftwareEngineering.SE refers to the first stable version, JDK 1.0.2 called Java 1.0, where it was removed.

现在,如果您尝试在 Java 1.0文档,您将找不到它,因为如前所述,它已在JDK 1.0.2(也称为Java 1.0)中删除。当您查看发布的链接的上次修改时间时,再次证明了这一点。您发布的链接的最后一次修改是在1996年2月。Java 1.0 / JDK 1.0.2在删除 private protected 时于1996年2月之后发布了。 em>,并根据规范,1996年8月。

Now if you try to search for it in the Java 1.0 documentation, you won't find it, because as mentioned earlier, it was removed in JDK 1.0.2, otherwise known as Java 1.0. This is proven again when you look at the "Last Modified" times for the link you posted. The link you posted was last modified in February of 1996. Java 1.0/JDK 1.0.2, when private protected was removed, was released after February of 1996, and according to the specification, August of 1996.

某些资料还解释了私有保护的原因,例如这个一个。引用:

Some sources also explain the reason for private protected, such as this one. To quote:


什么是受私人保护的?

早期,Java语言允许使用某些修饰符组合,其中之一是私有保护私有保护的含义是将可见性严格限制在子类中(并删除程序包访问权限)。后来有人认为这有点前后不一,过于复杂,不再受支持。[5]

Early on, the Java language allowed for certain combinations of modifiers, one of which was private protected. The meaning of private protected was to limit visibility strictly to subclasses (and remove package access). This was later deemed somewhat inconsistent and overly complex and is no longer supported.[5]

[5]受保护的修饰符在Java Beta2版本中进行了更改,并且同时显示了 private protected 组合。他们修补了一些潜在的安全漏洞,但使很多人感到困惑。

[5] The meaning of the protected modifier changed in the Beta2 release of Java, and the private protected combination appeared at the same time. They patched some potential security holes, but confused many people.

SoftwareEngineering.SE也支持这一点,说不是t会带来不一致和额外的复杂性,因此很早就将其删除。

And the SoftwareEngineering.SE also supports this, by saying that it wasn't worth the inconsistencies and extra complexity, so it was removed early on.

我对所有解释这就是也许,在橡树时代,两者都被允许共存(因此合并)。由于受保护的的含义已更改 1 ,因此可能需要允许私有受保护的同时进行。简介变得太复杂了,不值得,最后被删除了。到Java 1.0 / JDK 1.0.2发行时,它已被删除,因此无法在文档中找到。

My interpretation of all this is that maybe, back in the Oak days, both were allowed to coexist (hence the combination). Since protected's meaning had changed1, there may have been a need for allowing private and protected at the same time. The introduction became too complex and wasn't worth it, and was thus dropped in the end. By the time Java 1.0/JDK 1.0.2 rolled around, it had been dropped and thus cannot be found in the documentation.

1 橡木语言规范中,在第4.10节访问变量和方法中,请注意默认修饰符受保护

1In the Oak Language Specification, Section 4.10, Access to Variables and Methods, it is noted that the default modifier was protected:


默认情况下,类中的所有变量和方法均受保护

这与今天的默认程序包访问权限有很大不同。这可能为私有受保护的铺平了道路,因为私有的限制过于严格,而受保护的太宽容。

This is quite different from what we have today, the default package access. This may have paved the way for the need of private protected, because private was too restrictive and protected was too lenient.

这篇关于Java是否具有“私有保护”的功能?访问修饰符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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