Java Import 按需引入 潜龙勿用 Google规范

 

目录

Import规范

3.3.1 No wildcard imports

3.3.2 No line-wrapping

3.3.3 Ordering and spacing

3.3.4 No static import for classes

IDEA设置

参考


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语句看起来很长。

具体引用:https://www.cnblogs.com/dtts/p/4692480.html

 

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:

  1. All static imports in a single block.
  2. 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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值