Avoid repeated imports in Java: Inherit imports?

enums, import, inheritance, java

Solution

`import`s are just an aid to the compiler to find classes. They are active for a single source file and have no relation whatsoever to Java's OOP mechanisms.

So, no, you cannot “inherit” `import`s

Problem

Is there a way to "inherit" imports? Example: Common enum: ``` public enum Constant{ ONE, TWO, THREE } ``` Base class using this enum: ``` public class Base { protected void register(Constant c, String t) { ... } } ``` Sub class needing an import to use the enum constants convenient (without enum name): ``` import static Constant.*; // want to avoid this line! public Sub extends Base { public Sub() { register(TWO, "blabla"); // without import: Constant.TWO } } ``` and another class with same import ... ``` import static Constant.*; // want to avoid this line! public AnotherSub extends Base { ... } ``` I could use classic static final constants but maybe there is a way to use a common enum with the same convenience.

Original source