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

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

    There is no such thing as sub-package in java.

    java.util.stream is not a sub-pacakge of java.util.

    Therefore import java.util.* doesn't import the classes of java.util.stream.

    To import all the built in classes, you have to import them one package at a time. It's a better practice, though, to only import the classes that you actually need.

提交回复
热议问题