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.
Suppose I'm using only one class from another package only once which needs to be imported, say myPack.anotherPackage.ClassName.
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();
?
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.
In case if there is a conflict of ClassNames, then only in that case it is advisable to go for fully qualified names.