Java : The import collides with another import statement

爷,独闯天下 提交于 2020-01-11 18:49:59

问题


I have imported an Existing Java Application into my Workspace . I see that , a class with same name is present in different packages with in the Application.

For example a class named "Status.java" is present with in

com.tata.model.common.Status;
com.bayer.frontlayer.dao.Status;

When I tried to use both of them within a class, for example as shown below

import com.tata.model.common.Status;
import  com.bayer.frontlayer.dao.Status;
public class Adapter
{

}

It started giving an error in Eclipse stating

The import com.bayer.frontlayer.dao.Status collides with another import statement

Is there anyway to solve this without changing the name of the classes??

Thank you.


回答1:


You can use them explicitly without importing them, so the included package name differentiates between the two:

 //No imports required!
public class Adapter
{
     private com.tata.model.common.Status x;
     private com.bayer.frontlayer.dao.Status y;
}



回答2:


You can import just one of the classes and use the fully qualified name for the other one.

e.g.

import com.tata.model.common.Status;
//import  com.bayer.frontlayer.dao.Status;

class SomeClass{
    void someMethod(){
       new Status(); //  com.tata.model.common.Status
       new com.bayer.frontlayer.dao.Status(); //com.bayer.frontlayer.dao.Status
    }
}

Though I think it would be less confusing in your case if you just used the fully-qualified names for both classes.




回答3:


Directly apply full Class Names wherever applicable. Eg-

public class SomeClass {

public someMethod() {

com.myapp.someotherpackage.Status = "something";

com.some.other.package.Status = "otherthing";

if(com.myapp.someotherpackage.Status == com.some.other.package.Status) {

}
....
}
}


来源:https://stackoverflow.com/questions/8817130/java-the-import-collides-with-another-import-statement

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