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

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

问题描述

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

I have a doubt, whether the unused imports and unused objects in Java code creates 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.

与大多数性能问题一样,最好的方法是编写最清晰,最简单的代码,因为这样可以提高代码的可维护性,并有助于确保代码在更改后表现得相当好。 (Clever / Obtuse / Needless Verbose代码可以快速开始运行,但由于它只会被凡人改变它可能会变得更慢)

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天全站免登陆