导入两个具有相同名称的类。如何处理?

编程入门 行业动态 更新时间:2024-10-27 01:25:23
本文介绍了导入两个具有相同名称的类。如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

说我的代码如下:

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.

更多推荐

导入两个具有相同名称的类。如何处理?

本文发布于:2023-11-25 14:22:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630107.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何处理   名称   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!