1

我有一个静态字段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}。另外我希望每个类都覆盖generalMethod()of GeneralItem,但是这个方法是静态的,所以每个类都声明它自己的方法。

4

1 回答 1

1

Google Reflections Runtime 搜索和

Evo 类索引编译时间搜索

帮助。

于 2012-08-10T08:55:29.493 回答