【发布时间】:2012-08-27 19:37:37
【问题描述】:
我有许多 GUI 元素类型,并在 GUI 加载后直接在代码中使用它们。除非 GUI 加载器需要知道现有元素来创建它们,否则这将是可以的。
public final class VerticalBox extends Element {
...
private static final ElementType type;
static {
type = ElementType.register("VerticalBox",
new ElementType.ICreator() {
@Override
public Element create(GUI gui) {
return new VerticalBox(gui);
}
});
}
@Override
public ElementType getType() {
return type;
}
}
最简单的方法是在每个元素类中创建静态init 函数,但我需要为每个元素类调用init。
我在 JavaEE 中看到了一些注释,但它们的工作方式似乎相反。我可以从class 获得所有annotations,但不能从annotation 获得classes。我在这个主题上做了很多谷歌搜索。
【问题讨论】:
标签: java static annotations initialization