import java.util。*之间有什么区别?并导入java.util.Date; ? [英] What's the difference between import java.util.*; and import java.util.Date; ?

查看:94
本文介绍了import java.util。*之间有什么区别?并导入java.util.Date; ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想输出电流而且我写了

I just want to output current and I wrote

import java.util.*;

开头,

System.out.println(new Date());

主要部分。

但是我得到的是这样的:

But what I got was something like this:

Date@124bbbf

当我将导入更改为 import java.util.Date; 代码完美无缺,为什么?

When I change the import to import java.util.Date; the code works perfectly, why?

=================================== =

====================================

问题是,好的,我的源文件是Date.java,这就是原因。

The problem was, OK, my source file was "Date.java", that's the cause.

嗯,这完全是我的错,我让每个人都感到困惑; P

Well, it is all my fault, I confused everybody around ;P

感谢下面的每个人。这真的很好你了;)

And thanks to everyone below. It's really NICE OF YOU ;)

推荐答案

你可能在某处导入了其他一些Date类(或者你有一个Date类在你的包中,不需要导入)。使用import java.util。*,您正在使用其他日期。在这种情况下,最好在代码中明确指定java.util.Date。

You probably have some other "Date" class imported somewhere (or you have a Date class in you package, which does not need to be imported). With "import java.util.*" you are using the "other" Date. In this case it's best to explicitly specify java.util.Date in the code.

或者更好,尽量避免将类命名为Date。

Or better, try to avoid naming your classes "Date".

这篇关于import java.util。*之间有什么区别?并导入java.util.Date; ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆