Tuesday 15 June 2010

java - Is it bad to import unused packages? -



java - Is it bad to import unused packages? -

for instance when work in team @ same file , have partial understanding of different packages imported needed code work. alter code in file , find out code become redundant because of that. delete part , not know if whole code still depends on packages or not.

[of course of study bad can objectified in many ways: speed, read-abilty etc.]

you should utilize few of imports necessary, , don't utilize finish bundle imports java.util.*. today's ide's back upwards "organize imports" operation during unused imports removed.

if have bunch of unused imports , modify code, there chance add/change code refers classes covered unused imports. won't notice accidentally utilized them though might not intent.

if have minimum imports, if add together code refers new class, compiler notify showing errors, , giving possibility take class intend use.

also if utilize imports beyond referenced in program, increment chance break programme future releases of java or libraries use.

example: if programme uses java.util.hashset still import java.util.* , utilize 3rd party library import com.mylib.*, code might compile. if in future release 3rd party library adds class named com.mylib.hashset, you're code might not compile anymore because compiler might not able tell class wanted utilize (e.g. java.util.hashset or com.mylib.hashset). have imported java.util.hashset , e.g. com.mylib.someutil in first place, code still compile new version of 3rd party lib.

java import packages

No comments:

Post a Comment