未使用的导入和对象是否会对性能产生影响 [英] Does unused import and objects have a performance impact

查看:76
本文介绍了未使用的导入和对象是否会对性能产生影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怀疑,Java代码中未使用的导入和未使用的对象是否会对性能产生影响?

I have a doubt, whether the unused imports and unused objects in Java code create any performance impact?

假设对象已初始化并且从未使用过,会发生什么?
未使用的进口商品的成本是多少?

Suppose an object is initialized and never used, what happens? And what is the cost of unused imports?

推荐答案

这是一个非常常见的问题。

Its a very common question.

最好的方法是编写最清晰,最简单的代码,因为这可以提高代码的可维护性,并有助于确保代码即使在更改后也能正常运行。 (聪明的/难以理解的/不必要的,详细的代码一开始就可以快速运行,但是由于只是凡人而改变,它的运行速度会慢得多)。

Like most performance questions the best approach is to write the clearest and simplest code you can as this improves the maintainability of the code and helps ensure it performs reasonably well even after it is changed. (Clever/Obtuse/Needlessly Verbose code can run fast to start with but as it is changed by mere mortals it can get much slower)

未使用的进口商品对普通商品的影响很小

Unused imports have a trivial impact on the compiler, but there are no imports in the byte code or at runtime.

未使用的对象可以被优化掉,但是最好避免使用这些对象,因为它们几乎总是导致一些错误。性能影响,但更重要的是使阅读和维护您的代码更加困难。

Unused objects can be optimised away, but its best to avoid these as they almost always cause some performance impact, but more importantly make reading and maintaining your code more difficult.

这篇关于未使用的导入和对象是否会对性能产生影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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