Java import confusion

前端 未结 4 658
半阙折子戏
半阙折子戏 2020-12-18 23:08

What is the difference between:

java.awt.*;

and:

java.awt.event.*;

I find both in many programs.

4条回答
  •  梦毁少年i
    2020-12-18 23:45

    java.awt.* is not a regular expression, which is what I think you are expecting/thinking.

    java.awt.* will give you only the classes in that exact package, and not the nested packages. Imagine the name space collisions involved with below!

    import com.*
    

    It should be noted that it is considered bad practice to use *. Explicate class name imports are preferred.

    For further reading: Wikipedia: Namespace (Computer Science)

提交回复
热议问题