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

对着背影说爱祢 提交于 2019-11-30 13:56:34

问题


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.


回答1:


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



回答2:


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

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



回答3:


Without imports:

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


来源:https://stackoverflow.com/questions/4368120/how-to-use-two-class-with-the-same-name-in-different-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!