当前位置: 代码迷 >> Eclipse >> (转)Coding小技能-在Eclipse里简化静态引入
  详细解决方案

(转)Coding小技能-在Eclipse里简化静态引入

热度:18   发布时间:2016-04-23 12:35:07.0
(转)Coding小技巧-在Eclipse里简化静态引入

?

在eclipse里,有个黄金快捷键组合?ctrl + shift + O,大家应该不陌生吧!
当你敲完类名后触发它,它会帮你自动完成import,很实用的一个快捷键。

在JDK1.5发布后,java里引入了一个新的语法,static import。
该语法的本意是,简化静态属性在调用时的代码量,提高可读性。

但在eclipse里,如果你不提供类名,直接敲你想要的静态成员名或方法名,eclipse是无从查找的。
于是有些人,可能就使用人肉输入 import static xxx。(我就是其中之一)

其实,为了解决这个问题,eclipse早就引入了静态类预设功能。该功能的入口是
Windows -> Preferences -> Java -> Editor -> Content Assist -> Favorites
只要设置包含静态成员或方法的类,在编码过程中,你就可以直接敲名字了(或使用 alt + / 补全)。

?

原文:http://kenwublog.com/simplify-static-import-in-eclipse

?

?

Static Import?*

Static import support is still kind of clunky in Eclipse, e.g. copy/pasting code that uses static imports from one class to another will not bring the static imports with it, creating compile errors that are annoying to resolve.

Setting?Java > Code Style > Organize Imports > Number of static imports needed for *?to?1means that?MigrationKeywords.*?will be used as soon as you have a single static import keyword in use and makes the copy/paste experience nicer.

?

原文:http://joist.ws/eclipseTips.html

?

?

?

?

  相关解决方案