解决方法
导入声明部分是源代码的编译时元素,在运行时没有存在.在JVM字节码中,类型名称始终是完全限定的,除非您使用编写不良的编译器,否则二进制文件应仅包含实际使用的类型的名称.
类加载器用于完全不同的概念,与导入功能无关.
An import declaration allows a
static
member or a named type to be referred to by a simple name that consists of a single identifier. Without the use of an appropriateimport
declaration,the only way to refer to a type declared in another package,or astatic
member of another type,is to use a fully qualified name.A single-type-import declaration imports a single named type,by mentioning its canonical name.
A type-import-on-demand declaration imports all the accessible types of a named type or package as needed. It is a compile time error to import a type from the unnamed package.
A single static import declaration imports all accessible static members with a given name from a type,by giving its canonical name.
A static-import-on-demand declaration imports all accessible static members of a named type as needed.
参考
> JLS 7.5.1 Single-Type-Import Declaration
> JLS 7.5.2 Type-Import-on-Demand Declaration
> JLS 7.5.3 Single Static Import Declaration
> JLS 7.5.4 Static-Import-on-Demand Declaration
也可以看看
> Java Tutorials/Using package
members
> Java Language Guide/static import
各种进口相关问题
关于进口的语法作用:
> What is an import
called? – 这是一个声明,而不是声明
按需点对单一类型:
> Import package.* vs import package.SpecificType
> Why is using a wild card with a Java import statement bad?
> What’s the difference between import java.util.*;
and import java.util.Date;
?
导入静态:
> What does the static
modifier after import
mean?
> What is a good use case for static import of methods?
> Should I use static import?
绩效相关问题:
> Does importing of packages change visibility of classes? – 绝对不!
> Do multiple import statements in a program affect performance? – NOPE!
> Any reason to clean up unused imports in Java,other than reducing clutter?