在发现有相同名称的类出现时,可以使用类的全限定名来区分不同模块中的同名类。例如,假设我们有两个包分别为com.example.module1和com.example.module2,在这两个包中都有名为Utils的类。我们可以在使用时分别使用全限定名com.example.module1.Utils和com.example.module2.Utils来区分它们。
示例代码:
在com.example.module1中:
package com.example.module1;
public class Utils {
//...
}
在com.example.module2中:
package com.example.module2;
public class Utils {
//...
}
在另一个模块中使用时:
import com.example.module1.Utils;
import com.example.module2.Utils;
public class Test {
public void test() {
com.example.module1.Utils utils1 = new com.example.module1.Utils();
com.example.module2.Utils utils2 = new com.example.module2.Utils();
//使用utils1和utils2执行不同的操作
}
}
上一篇:AndroidStudio本地Java应用开发中是否有热重载功能?
下一篇:AndroidStudio崩溃了,出现“FATALEXCEPTION,androidstudiokeepscrashingforabutton。