Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import some classes in same package

I want to import all the classes in a package at once, not one by one. I tried import pckName.*; but it's not working.

Example: I have class X in package name pack1.

package pack1;

public class X {
.
.
}

and I have class Y in the same package.

package pack1;

public class Y {
.
.
}

I don't want to have to import them like this:

import pack1.X;
import pack1.Y;

Why? Because my package (har!) has a lot of classes and it's annoying to add them one by one. Is there a way to import them all at once?

like image 321
asaf Avatar asked Feb 12 '13 09:02

asaf


1 Answers

You should use:

import pack1.*;

Add this line to the classes from the other packages. E.g.:

package pack2;

import pack1.*;

public class XPack2 {
    // ...
    // X x = new X();
    // ...
}

Just make sure, that your classpath is correctly set.

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

Then you should explicitly write fully qualified name of the class.

like image 120
Ostap Andrusiv Avatar answered Oct 08 '22 07:10

Ostap Andrusiv