Why is using a wild card with a Java import statement bad?

后端 未结 17 1615
梦谈多话
梦谈多话 2020-11-21 13:07

It is much more convenient and cleaner to use a single statement like

import java.awt.*;

than to import a bunch of individual classes

17条回答
  •  爱一瞬间的悲伤
    2020-11-21 13:51

    Importing all the classes in a package is considered a blind approach. A major reason for this is that it clutters the class namespace and could lead to conflicts between classes in different packages with the same name.

    Specifically populating the necessary classes avoids that problem and clearly shows which versions were wanted. This is good for code maintainability.

提交回复
热议问题