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

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

问题描述

我已经尝试在网上和我自己的知识范围内找到这个问题的答案,但我似乎找不到明确的答案.

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 语句 之间有什么区别(如果有):

What is the difference, if any, between using an import statement:

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 让你的代码更可读,因为你不是用完整的包来弄乱代码.

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:导入语句与完全限定名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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