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

后端 未结 17 1962
梦谈多话
梦谈多话 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:54

    In a previous project I found that changing from *-imports to specific imports reduced compilation time by half (from about 10 minutes to about 5 minutes). The *-import makes the compiler search each of the packages listed for a class matching the one you used. While this time can be small, it adds up for large projects.

    A side affect of the *-import was that developers would copy and paste common import lines rather than think about what they needed.

提交回复
热议问题