目录
3.3.4 No static import for classes
Import规范
摘录自Google开发规范
3.3.1 No wildcard imports
Wildcard imports, static or otherwise, are not used.
3.3.1 请勿使用通配符引入(按需引入)
无论是静态引入还是其他的,不要使用通配符引入
原因:
1 提高编译速度。
2 避免命名冲突。(例如:当你import java.awt.*;import java.util.*后,使用List的时候编译器将会出编译错误)
当然,使用单类型导入会使用你的import语句看起来很长。
3.3.2 No line-wrapping
Import statements are not line-wrapped. The column limit (Section 4.4, Column limit: 100) does not apply to import statements.
3.3.2 引入语句(一个import)不换行
引入语句不换行,4.4节的规则(一行最多100个字符),不适用于import
3.3.3 Ordering and spacing
Imports are ordered as follows:
- All static imports in a single block.
- All non-static imports in a single block.
If there are both static and non-static imports, a single blank line separates the two blocks. There are no other blank lines between import statements.
Within each block the imported names appear in ASCII sort order. (Note: this is not the same as the import statements being in ASCII sort order, since '.' sorts before ';'.)
3.3.3 排序和空行
imports语句按照下述规则:
1. 所有的静态引入在一个代码块
2.所有的非静态引入在一个代码块
如果静态和非静态引入同时存在,需要一个空行隔开这两种引入。除此之外import没有其他空行来进行间隔
在同一个引入代码块中,按照ASCII的方式进行排序(说明:这不等同于引用语句完全按ASCII排序,因为“.”排在“;”之前,【个人认为:"."应该是优先于所有其他字符】)
3.3.4 No static import for classes
Static import is not used for static nested classes. They are imported with normal imports.
静态引入不用于静态内部类,它们使用普通引用
IDEA设置
将 class count to use import "*"
设置一个很大的值。只有相同路径下的引用超过该数值,IDEA才会归并这些import为 按需引入
参考
google guide
https://google.github.io/styleguide/javaguide.html#s3.3-import-statements
how to forbid wildcard import by IDEA
https://stackoverflow.com/questions/3348816/intellij-never-use-wildcard-imports
https://www.cnblogs.com/dtts/p/4692480.html