有没有办法“继承”进口?避免在Java中重复导入:继承导入?
实施例:
普通的枚举:使用该枚举
public enum Constant{ ONE, TWO, THREE }
基类:
public class Base {
protected void register(Constant c, String t) {
...
}
}
子类需要导入使用枚举常数方便(无枚举名):
import static Constant.*; // want to avoid this line!
public Sub extends Base {
public Sub() {
register(TWO, "blabla"); // without import: Constant.TWO
}
}
,并用相同的导入另一个类...
import static Constant.*; // want to avoid this line!
public AnotherSub extends Base {
...
}
我可以使用传统的静态的最后常数,但也许没有使用常见的枚举用同样的便利的方式。
如果使用IDE(Eclipse的说),那么进口将当您使用类自动添加。 – medopal 2010-01-11 13:35:23