Search code examples
javaclassimportpackageproject-structure

Import Java classes once for all package


Let's say, I have the following structure:

  • src.main.java
    • first
      • one.java
      • two.java
      • three.java
    • second
      • alpha.java
      • beta.java
      • gamma.java

I want all classes from first package to be imported in all classes in my second package.

Now I'm just specifying for every class in second package:

import first.*;

Can I import once for all classes in package?


Solution

  • No, it cannot be done.

    I don't see why this is such a hardship.

    A better solution would be to use an IDE that can add the imports as you need them.

    I'd also recommend spelling each one out individually rather than using the star notation, even if you need to import all of them. It documents your intent better, and that IDE can make it transparent to you.