本文介绍了导入两个具有相同名称的类。如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我的代码如下:
import java.util.Date; import my.own.Date; class Test{ public static void main(String [] args){ // I want to choose my.own.Date here. How? .. // I want to choose util.Date here. How ? } }我是否应该是完全合格的班级名称?我能摆脱进口声明吗?这种场景在现实世界编程中是否常见?
Should I be full qualified class names? Can I get rid of the import statements? Is such a scenario common in real world programming?
推荐答案您可以省略import语句并使用整个路径引用它们。例如:
You can omit the import statements and refer to them using the entire path. Eg:
java.util.Date javaDate = new java.util.Date() my.own.Date myDate = new my.own.Date();但我会说使用两个具有相同名称和类似功能的类通常不是最好的想法,除非你能说清楚哪个是哪个。
But I would say that using two classes with the same name and a similiar function is usually not the best idea unless you can make it really clear which is which.
更多推荐
导入两个具有相同名称的类。如何处理?
发布评论