java 如何在不同的包中使用两个同名的类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4368120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:03:56  来源:igfitidea点击:

How to use two class with the same name in different packages?

javanaming-conventionspackages

提问by Drahakar

How can I access two classes with the same name in different packages?

如何访问不同包中具有相同名称的两个类?

foo.bar.myClass.class

and

foo.myClass.class

All of this in the same class

所有这些都在同一个班级

@TestRunner(Suite.class)
@SuiteTest({bar.myClass.class, myClass.class})

Thank you.

谢谢你。

回答by Jigar Joshi

you will have to import one and other you will be writting fully qualified path

你将不得不导入一个和另一个你将编写完全合格的路径

for example in your code:

例如在您的代码中:

import foo.bar.myClass;

.
.
.
myClass ob; // this  will refer to foo.bar.myClass 
foo.myClass ob1 ;//this  will refer to foo.myClass

回答by Vincent Ramdhanie

You need to use the fully qualified names of the classes.

您需要使用类的完全限定名称。

 foo.bar.myClass myvar;
 foo.myClass anothervar;

回答by Boris Pavlovi?

Without imports:

无进口:

@TestRunner(Suite.class)
@SuiteTest({foo.bar.myClass.class, foo.myClass.class})