任何理由清理未使用的进口Java,除了减少杂乱? [英] Any reason to clean up unused imports in Java, other than reducing clutter?

查看:90
本文介绍了任何理由清理未使用的进口Java,除了减少杂乱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么好的理由避免Java中未使用的import语句?根据我的理解,他们在编译器,所以很多未使用的导入将不会对编译的代码有任何影响。只是为了减少杂乱和避免命名冲突下来了吗?

Is there any good reason to avoid unused import statements in Java? As I understand it, they are there for the compiler, so lots of unused imports won't have any impacts on the compiled code. Is it just to reduce clutter and to avoid naming conflicts down the line?

(我问,因为Eclipse给出了一个警告,对未使用的导入,这是一种恼人,当我' m开发代码,因为我不想删除导入,直到我确定我完成了设计类。)

(I ask because Eclipse gives a warning about unused imports, which is kind of annoying when I'm developing code because I don't want to remove the imports until I'm pretty sure I'm done designing the class.)

推荐答案

我不认为如果你不删除导入,性能问题或类似的东西。

I don't think that performance problems or something like that are likely if you are not removing the imports.

但可能存在命名冲突,在极少数情况下

But there could be naming conflicts, in rare cases like importing the list interface.

在Eclipse中,您可以随时使用快捷方式(取决于操作系统 - Win: Ctrl + SHIFT + O 和Mac: COMMAND + SHIFT + O )组织导入。 Eclipse然后清理导入部分删除所有的stale导入等。如果你需要一个导入的东西eclipse将自动添加它们在您完成语句与 Ctrl + SPACE

In Eclipse you can always use a shortcut (depends on OS - Win: Ctrl + SHIFT + O and Mac: COMMAND + SHIFT + O) to organize the imports. Eclipse then cleans up the import section removes all the stale imports etc. If you are needing a imported thing again eclipse will add them automatically while you are completing the statement with Ctrl + SPACE. So there is no need in keeping unused code in you class.

由于一直未使用的代码会分散你和其他人的注意力,因为在阅读代码时,你会在活动代码中留下一些东西,因为可能我以后需要它,大多被视为不良做法。

As always unused code will distract you and other people while reading the code and leaving something in your active code because of maybe I need it later is mostly seen as bad practice.

这篇关于任何理由清理未使用的进口Java,除了减少杂乱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆