使用反射

时间:2017-11-03 11:16:27

标签: java reflection annotations

我想迭代一些使用约束验证注释注释的JAXB对象,并通过反射以编程方式检索注释。我尝试使用以下代码:

PropertyUtilsBean pub= new PropertyUtilsBean();
    PropertyDescriptor[] pds = pub.getPropertyDescriptors(object);

    for (PropertyDescriptor pd : pds) {
        Class<?> propClazz = pd.getPropertyType();
        Annotation[] annotations = propClazz.getDeclaredAnnotations();
        for(Annotation a : annotations) {
            System.out.println(a.toString());
        } 

但是我只能通过JAXB对象获取注释,例如@XmlType等。有没有人有任何建议?

0 个答案:

没有答案