使用较短的程序包名称来解决冲突的名称 [英] Use shorter package names to resolve conflicting name
问题描述
如果名称冲突,是否有办法在Java中使用缩短的软件包名称?
Is there a way to use a shortened package name in Java if you have conflicting names?
例如,如果冲突不在com.domain.a
中,则无需输入com.domain.a.b
,您只需说b.SomeClass
而不是com.domain.a.b.SomeClass
. C#具有与此类似的功能.
For instance, instead of typing out com.domain.a.b
, if the conflict is in com.domain.a
, you can just say b.SomeClass
instead of com.domain.a.b.SomeClass
. C# has a feature similar to this.
推荐答案
否,您可以使用标准名称或简称.您可能正在寻找模糊
No, you either use fully qualified names or short names. You're probably looking for obscuring
简单名称可能会在可能存在的上下文中出现 解释为变量,类型或包的名称.在这些 在这种情况下,第6.5节的规则指定将选择一个变量 优先于类型,并且优先选择类型 到一个包装.因此,有时可能无法引用 通过其简单名称的可见类型或包声明.我们说 这样的声明被遮盖了.
A simple name may occur in contexts where it may potentially be interpreted as the name of a variable, a type, or a package. In these situations, the rules of §6.5 specify that a variable will be chosen in preference to a type, and that a type will be chosen in preference to a package. Thus, it is may sometimes be impossible to refer to a visible type or package declaration via its simple name. We say that such a declaration is obscured.
如果遵循Java命名约定,那么您实际上应该不会有任何问题.
If you follow Java naming conventions, you shouldn't really have any issues.
这篇关于使用较短的程序包名称来解决冲突的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!