What About using import java.* for using all sub-packages under the package 'java'?

前端 未结 7 582
一生所求
一生所求 2021-01-13 19:06
import java.*;

Why cannot I do this importing ?? Instead of importing the all class in a particular sub-package of the package \'java\' , I tried t

7条回答
  •  感情败类
    2021-01-13 19:47

    Because import some.example.Type; is only to import types not the packages. import some.example.*; means you're importing all the Types contained inside some.example package not the other packages inside it.

    This is because import means the code of that file will be available for your program at run time and package itself doesn't contain any code. It contains files which have the code.

    That's why you can't import all the built-in code in a single import statement. At max you can import in a single statement is all the code available in different files within a package and you know the way import some.example.*;

提交回复
热议问题