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

后端 未结 17 1624
梦谈多话
梦谈多话 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 14:00

    It clutters your namespace, requiring you to fully specify any classnames that are ambiguous. The most common occurence of this is with:

    import java.util.*;
    import java.awt.*;
    
    ...
    List blah; // Ambiguous, needs to be qualified.
    

    It also helps make your dependencies concrete, as all of your dependencies are listed at the top of the file.

提交回复
热议问题