Java:import语句与完全限定名称? [英] Java: import statement vs fully qualified name?

查看:173
本文介绍了Java:import语句与完全限定名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在网上和我自己的知识中找到答案,但我似乎无法找到明确,明确的答案。

I've tried finding an answer to this both online and in my own set of knowledge, but I cannot seem to find a definitive, clear answer.

假设我只使用另一个包中的一个类只需要导入一次,例如 myPack.anotherPackage.ClassName

Suppose I'm using only one class from another package only once which needs to be imported, say myPack.anotherPackage.ClassName.

使用 导入语句 之间有什么区别():

import myPack.anotherPackage.ClassName;

与使用 完全限定名称

versus using a fully qualified name:

myPack.anotherpackage.ClassName classInst = new myPack.anotherpackage.ClassName();

显然这个问题仅适用于 ClassName 仅使用一次。

Obviously this question only applies if ClassName is only used once.

推荐答案

导入语句 使您的代码更易于可读,因为您是不要使用完整的包使代码混乱。

Import statements make your code more readable, since you are not cluttering the code with the complete package.

如果存在 ClassNames 的冲突,那么只有在这种情况下,建议选择 完全限定名称

In case if there is a conflict of ClassNames, then only in that case it is advisable to go for fully qualified names.

这篇关于Java:import语句与完全限定名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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