问题描述
为什么我们使用反向域名,如 com.something.或 org.something.java包的结构?我知道这会带来某种独特性,但我们为什么需要这种独特性呢?
Why do we use reverse domain name like com.something. or org.something. structure for java packages? I understand this brings in some sort of uniqueness, but why do we need this uniqueness?
推荐答案
全局唯一的包名避免了不同来源的库之间的命名冲突.不是创建一个新的全球名称中央数据库,而是使用域名注册.来自 JLS:
Globally unique package names avoid naming collisions between libraries from different sources. Rather than creating a new central database of global names, the domain name registry is used. From the JLS:
建议的约定生成唯一的包名称是只是一种捎带包裹的方法命名约定现有的、广为人知的唯一名称注册表,而不必创建一个包名称的单独注册表.
The suggested convention for generating unique package names is merely a way to piggyback a package naming convention on top of an existing, widely known unique name registry instead of having to create a separate registry for package names.
这篇关于java包结构反向域名有什么意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!