[英]How can I avoid a name conflict between a class and a package in Java?
I have two projects, Main
and Core
. 我有两个项目, Main
和Core
。 I have a package called com.package.Sample
(along with its contents) and a class called Sample
in package com.package
. 我有一个名为com.package.Sample
的包(及其内容)和一个名为Sample
的包com.package
。 If I were to include both in Main
, I would run into an error with one being unable to resolve - in my actual case it was the Sample
class that could not be resolved. 如果我要在Main
包含两者,我会遇到一个无法解决的错误 - 在我的实际情况中,它是Sample
类无法解析。 We have ant scripts that builds and that has always worked. 我们有构建的ant脚本,并且一直有效。
However, carefully examining what was required of each project, I noticed that I could move the package com.package.Sample
into Core
along with its dependencies that were in Main
. 但是,仔细检查每个项目所需的内容,我注意到我可以将软件包com.package.Sample
与Main
依赖项一起移动到Core
中。 The Sample
class technically belonged inside of Main
so I did not move it. Sample
类技术上属于Main
内部所以我没有移动它。 This allowed me to build successfully within Eclipse. 这使我能够在Eclipse中成功构建。
A couple of things I'm wondering about: 我想知道几件事:
Sample
class. 在检查冲突之前,我认为最好的解决方案是重新计算Sample
类。 com.package.Sample
out of Main
. 但是,如果我无法将包com.package.Sample
移出Main
。 What should I do? 我该怎么办? Or is this a case of it will never build? 或者这是一个永远不会建立的情况? To answer your bullets, respectively: 分别回答你的子弹:
Good luck! 祝好运!
Package names should be all lowercase, class names should start with a capital. 包名称应全部小写,类名应以大写字母开头。 Following this practice makes sure that problems like you describe never occur. 遵循这种做法可确保您描述的问题永远不会发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.