Import multiple classes into one package

I want to import all classes into a package at once, and not one by one. I tried import pckName.*; but it does not work.

Example: I have class X in the package name pack1.

 package pack1; public class X { . . } 

and I have class Y in the same package.

 package pack1; public class Y { . . } 

I do not want to import them as follows:

 import pack1.X; import pack1.Y; 

Why? Because my package (har!) Has many classes, and it is annoying to add them one at a time. Is there a way to import them right away?

+7
source share
1 answer

You should use:

 import pack1.*; 

Add this line to classes from other packages. For example:.

 package pack2; import pack1.*; public class XPack2 { // ... // X x = new X(); // ... } 

Just make sure your classpath is set correctly.

Problems can arise if you have 2 classes with the same name: pack1.X and pack2.X .

Then you must explicitly write the fully qualified class name.

+6
source

All Articles