Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

import java.*;

Why cannot I do this import? Instead of importing all classes in a particular sub-package of the package 'java', I tried to import all the sub-packages under the the 'java' package.

How can I import all the built-in classes?

like image 738
R S Muthu Kumaran Avatar asked Dec 06 '22 22:12

R S Muthu Kumaran


1 Answers

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.

like image 100
Eran Avatar answered Jan 10 '23 21:01

Eran