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

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

    Forget about cluttered namespaces... And consider the poor soul who has to read and understand your code on GitHub, in vi, Notepad++, or some other non-IDE text editor.

    That person has to painstakingly look up every token that comes from one of the wildcards against all the classes and references in each wildcarded scope... just to figure out what in the heck is going on.

    If you're writing code for the compiler only - and you know what you're doing - I'm sure there's no problem with wildcards.

    But if other people - including future you - want to quickly make sense of a particular code file on one reading, then explicit references help a lot.

提交回复
热议问题