Eclipse-在模棱两可的导入中自动导入java.util类 [英] Eclipse - auto import java.util classes on ambiguous imports
问题描述
Eclipse是否有一种方法自动导入 java包中的类为java.util.List
,而无需在每个类中显式选择它?
Is there a way Eclipse will auto import classes from java package as java.util.List
without the need to choose it explicitly in every class?
(即使没有 Ctrl + Shift + O )
(even without Ctrl + Shift + O)
当我编写列表并蚀自动导入java.util.List
时,而不是将无关列表建议为org.apache.xmlbeans.impl.xb.xsdschema.ListDocument.List
When I write List and eclipse auto import java.util.List
instead of suggesting irrelevant List as org.apache.xmlbeans.impl.xb.xsdschema.ListDocument.List
我知道我可以按类型过滤器排除,但我只希望将特定对象(如List)自动导入.
I know I can exclude by Type Filters, but I just want specific objects as List to be automatically imported.
推荐答案
保存时自动组织导入语句
- 转到窗口>首选项> Java>编辑器>保存操作.
- 选择保存时执行选定的操作(默认情况下为关闭).
- 确保已选中组织导入"(默认情况下处于启用状态).
让Eclipse将通配符(.*)导入到同一包中,或者 始终将它们展开
Let Eclipse collapse imports in the same package a wildcard (.*) or always expand them
- 转到窗口>首选项> Java>代码样式>组织导入.
- 将.*所需的进口数量"的值更改为0.
- (可选)将.*所需的静态导入数的值更改为0.
使用类型过滤器排除不需要的软件包
- 转到窗口>首选项> Java>外观>键入过滤器.
- 单击添加"以添加包/类.
- 输入java.awt.List(如果您不打算使用任何AWT类,则输入java.awt.*.
其中一些其他功能
-
折叠:默认情况下,Eclipse将所有导入语句折叠为一行,因此您的类占用的屏幕空间更少.您可以通过以下方式更改此设置:转到窗口">首选项">"Java">编辑器">折叠",然后取消选择导入".
Folding: By default, Eclipse folds all import statements into one line so your class takes up less space on the screen. You can change this by going to Window > Preferences > Java > Editor > Folding and deselecting Imports.
排序:如果您真的很了解软件包的顺序,则可以转到窗口">首选项">"Java">代码样式">组织导入",然后将软件包的顺序定义为您想让Eclipse订购它们.不过,这确实不值得付出努力,所以我跳过了.
Sorting: If you’re really particular about the order of packages, you can go to Window > Preferences > Java > Code Style > Organize Imports and define the order of the packages as you want Eclipse to order them. It’s not really worth the effort though so I’d skip it.
这篇关于Eclipse-在模棱两可的导入中自动导入java.util类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!