I want to know a class with some member variable comments, I use BeanInfo beanInfo = Introspector.getBeanInfo(User.class) to introspect the class and use BeanInfo.getPropertyDescriptors() to find a specific property and use Class type = propertyDescriptor.getPropertyType() for get the Class property.
But I don't know how to add annotations to a member variable?
I tried type.getAnnotations() and type.getDeclaredAnnotations() , but both return class annotations, not what I want. For example:
class User { @Id private Long id; @Column(name="ADDRESS_ID") private Address address; // getters , setters } @Entity @Table(name = "Address") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) class Address { ... }
I want to get the address annotation: @Column, not the Address annotation class (@Entity, @Table, @Cache). How to reach it? Thank.
java reflection annotations
smallufo Dec 15 '10 at 17:48 2010-12-15 17:48
source share