简体   繁体   English

Eclipse 可以在不添加通配符的情况下自动完成导入语句吗?

[英]Can Eclipse auto-complete import statement without adding wildcard?

当我在 Eclipse 中输入 import 语句时,会给出自动完成选项的列表,但是当我选择一个时,它会为整个包添加一个通配符,例如org.apache.* ,但我想自动完成只是包名称并继续输入子包或类,例如org.apache.log4j.Logger

Eclipse has a setting for the number of imports needed in order to stop listing the classes one by one and use the package.* syntax instead. Eclipse 对所需的导入数量进行了设置,以便停止一一列出类并改用package.*语法。

You can change that setting by going to Window>Preferences>Java>Code Style>Organize Imports.您可以通过转到“窗口”>“首选项”>“Java”>“代码样式”>“组织导入”来更改该设置。

Put a large number into the edit boxes at the bottom.在底部的编辑框中输入一个大数字。

Rather than typing individual import statements by hand, consider just typing the names of classes where you need them, then using Content Assist ( Ctrl + Space or Command + Space on OS X) and let Eclipse auto-insert the import statement for you automatically.与其手动输入单个import语句,不如考虑只在需要它们的地方键入类的名称,然后使用 Content Assist(在 OS X 上为Ctrl + SpaceCommand + Space )并让 Eclipse 自动为您自动插入导入语句。 It won't use a wildcard import unless you've configured it to do that at a certain threshold (see @f1sh's answer).它不会使用通配符导入,除非您已将其配置为在某个阈值下执行此操作(请参阅 @f1sh 的答案)。

使用Ctrl + Space键入包名,eclipse 将显示相关包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM