Does unused import and objects have a performance impact

后端 未结 5 1042
一生所求
一生所求 2020-11-29 04:49

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 happen

5条回答
  •  感动是毒
    2020-11-29 05:40

    Unused imports have no performance impact at runtime. It is purely a namespace mechanism. Nonetheless, you should always import only what you need for readability and avoid namespace collisions which are a nuisance.

    Apart from code readability and hence maintainability of code, there may be faster compilation of java code (however, unnoticeable) by tidying up imports, but runtime performance is not impacted, since byte code generated is not impacted by untidy imports. Byte code generated remains the same.

提交回复
热议问题