Added support for instantiating annotation instances
Added method AnnotationInfo#loadClassAndInstantiate()
that loads the class returned by AnnotationInfo#.getClassInfo()
, and then returns an Annotation
instance that can be cast to the specific annotation type represented by the AnnotationInfo
object.
This method call makes annotations significantly easier to work with (assuming you don't mind calling the classloader to load the annotation class and any classes in the annotation parameter values), since you can just call the methods of the returned Annotation
instance directly once you have cast it to the correct annotation type.
This method is implemented by dynamically instantiating an InvocationHandler
that emulates the annotation class for the specific annotation instance represented by the AnnotationInfo
object. The InvocationHandler
retrieves annotation parameters from the AnnotationInfo
object, overriding any annotation default parameter values with instance-specific values. (An InvocationHandler
is needed because annotations can't be directly instantiated.)
Changed AnnotationParameterValue#getValue()
to return primitive arrays where possible
Changed AnnotationParameterValue#getValue()
to return primitive- and String-typed arrays (e.g. int[]
, 'String[], etc.) for primitive-array-typed annotation parameter values, rather than
Object[]arrays of boxed types or Strings. This brings the
AnnotationParameterValueAPI more in line with the standard Java
Annotation` API.
(This method still returns all values cast as Object, since there can be many different return types.)
This is a breaking change for AnnotationParameterValue#getValue()
, hence the version bump to 4.4.x.