Java:使用包的约定?
我有 PHP 背景,由于过去缺乏命名空间,我使用了 Zend Framework 风格的“包”。例如,如果我有一个抽象类 Player 和子类 Player_Human、Player_DumbComputer、Player_Minimax 等。我会将 Player 放在主目录中,并将其子类放在目录 /Player/ 中。它试图在 Java 中做类似的事情,但我遇到了名称冲突——我有一个包 blah.Player 和一个类 blah.Player。我该如何避免这种情况?这方面的常见做法是什么?
I am coming from a PHP background, and due to the lack of namespaces in the past I have used Zend Framework style "packages". For example, if I have an abstract class Player and children Player_Human, Player_DumbComputer, Player_Minimax, etc. I would put Player in the main directory and put it's children in a directory /Player/. It tried to do something similar in Java, but I got a name-clash -- I have both a package blah.Player and a class blah.Player. How do I avoid this? What is the common practice regarding this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自JavaTM编程语言的代码约定:
From Code Conventions for the JavaTM Programming Language:
Java 包名称始终为小写字母,而类名称始终以大写字母开头,并且是驼峰式名称(无下划线)。所以你的结构应该是:
Java Package names are always in lower case while the Class names always start with an upper case letter and are camel case names (no underscores). So your structure should be:
Java 广泛使用包名称约定。
Java has widely used conventions for package names.