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

前端 未结 7 577
一生所求
一生所求 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:58

    Why? Because Java by design is divided into different packages. This way you can't pollute your namespace with all the classes that exist, and you have to actually specify what classes in which namespace you intend to use.

    In java, packages don't relate to each other - there is no hierarchy (even if it would look like it), just flat names of packages.

    As to how you could circumvent that, I'd think the only way would be to iterate all packages and generate your java code based on that iteration. There is no straight way to do it.

    0 讨论(0)
提交回复
热议问题