Java import confusion

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

What is the difference between:

java.awt.*;

and:

java.awt.event.*;

I find both in many programs.

4条回答
  •  忘掉有多难
    2020-12-18 23:47

    Packages in Java are not nested.

    When you import java.awt.*, you are only importing all the classes and interfaces that are in the package java.awt - you are not importing all the packages that are under java.awt, such as java.awt.event.

    Even though it looks like packages are nested (i.e., it looks like as if java.awt.event is a "subpackage" of java.awt), this is not really the case. You should regard java.awt and java.awt.event as two different, unrelated packages that happen to have a common part in their names.

提交回复
热议问题