【发布时间】:2012-08-10 16:55:29
【问题描述】:
我有一个静态字段public static Class[] items; 我希望在应用程序开始时用具有@ItemExample 注释的类填充它。示例类(简化):
public class ItemUtil{
public static Class[] itemClasses;
public static void actionsWithAllItemClasses(
//call some general method of classes in array using reflection API
)
}
@ItemExample
public class Item1 extends GeneralItem{
public static void generalMethod(){
//Item 1 specific action
}
}
@ItemExample
public class Item2 extends GeneralItem{
public static void generalMethod(){
//Item2 specific action
}
}
所以在启动(部署,在 ServletCONtextListneres 开始执行之前)应用程序(在 Tomcat 中运行)item classes=={Item1.class, Item2.class} 的时间。另外我希望每个类都覆盖GeneralItem的generalMethod(),但是这个方法是静态的,所以每个类都声明它自己的方法。
【问题讨论】:
标签: java static annotations aop aspectj