Java语言规范基于JavaSE9 第七章 包和模块(二)

7.1 Package Members

7.1 包成员

The members of a package are its subpackages and all the top level class types (§7.6, §8 (Classes)) and top level interface types (§9 (Interfaces)) declared in all the compilation units (§7.3) of the package.

包的成员有其子包,以及在其所有编译单元(第7.3节)中声明的所有顶层类类型(第7.6节、第8章)和顶层接口(第9章)。

For example, in the Java SE Platform API:

例如,在 Java SE平台的API中:

• The package java has subpackages awt, applet, io, lang, net, and util, but no compilation units.

  • java包有子包awt,applet,io,lang,net和util,但是没有任何编译单元。

• The package java.awt has a subpackage named image, as well as a number of compilation units containing declarations of class and interface types.

  • Java.awt包有名字为image的子包,以及大量包含类和接口类型声明的编译单元。

If the fully qualified name (§6.7) of a package is P, and Q is a subpackage of P, then P.Q is the fully qualified name of the subpackage, and furthermore denotes a package.

如果包的完全限定名(第6.7节)是P,而Q是P的子包,那么P .Q就是该子包的完全限定名,表示一个包。

A package may not contain two members of the same name, or a compile-time error results.

包不能包含两个同名的成员,否则就会产生编译时错误。

Here are some examples:

下面是一些例子:

• Because the package java.awt has a subpackage image, it cannot (and does not) contain a declaration of a class or interface type named image.

  • 因为java.awt包有一个子包image,所以它不能(也没有)包含命名为image 的类或接口类型的声明。

• If there is a package named mouse and a member type Button in that package (which then might be referred to as mouse.Button), then there cannot be any package with the fully qualified name mouse.Button or mouse.Button.Click.

  • 如果有一个包命名为mouse,而这个包中有一个成员类型Button(因此可以用mouse.Button来引用该类型),那么就不能有任何包具有完全限定名mouse.Button或mouse.Button.Click。

• If com.nighthacks.java.jag is the fully qualified name of a type, then there cannot be any package whose fully qualified name is either com.nighthacks.java.jag or com.nighthacks.java.jag.scrabble.

  • 如果com.nighthacks.java.jag是某个类型的完全限定名,那么就不能有任何包具有完全限定名com.nighthacks.java.jag或com.nighthacks.java.jag.scrabble。

It is however possible for members of different packages to have the same simple name. For example, it is possible to declare a package:

但是,对于不同包中的成员,还是可以具有相同的简单名的。例如,可以声明下面的包:

package vector;
public class Vector { Object[] vec; }

that has as a member a public class named Vector, even though the package java.util also declares a class named Vector. These two class types are different, reflected by the fact that they have different fully qualified names (§6.7). The fully qualified name of this example Vector is vector.Vector, whereas java.util.Vector is the fully qualified name of the Vector class included in the Java SE Platform. Because the package vector contains a class named Vector, it cannot also have a subpackage named Vector.

它有一个成员,即命名为Vector的public类,尽管java.util包中也声明了一个命名为Vector的类。这两个类的类型是不同的,这反映了这样一个事实:它们具有不同的完全限定名(第6.7节)。这个示例中的Vector的完全限定名是vector.Vector,而java.util.Vector是在Java SE平台中包含Vector类的完全限定名。因为vector包包含命名为Vector的类,因此它不能有命名为Vector的子包。

The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level type (§7.6) declared in that package.

包的层次化命名结构意在提供一种便捷方式使得对相关包的组织更加方便,但是除了能够阻止包中某个子包与在该包中声明的顶层类型(第7.6节)具有相同名字这种情形发生之外,它本身并没有其他特殊的意义。

For example, there is no special access relationship between a package named oliver and another package named oliver.twist, or between packages named evelyn.wood and evelyn.waugh. That is, the code in a package named oliver.twist has no better access to the types declared within package oliver than code in any other package.

例如,在命名为oliver的包和另一个命名为oliver.twist的包之间,或者在命名为evelyn.wood和evelyn.waugh的包之间,不存在任何特殊的访问关系。即,在命名为oliver.twist的包中的代码与在其他任何包中的代码相比,对oliver内部声 明的类型并没有任何更多的访问权限。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值