Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Using the Annotations reader class

You can retrieve the backport175 annotations as well as regular Java 5 annotations (when running Java 5) at runtime using the API in the Annotations class.

You retreive the annotations by specifying the:

  • name of the annotations - this must be the fully qualified name of the annotation interface.
  • class or member that is annotated - this is the java.lang.Class (for class level annotations) or one of the member class in the java.lang.reflect.* package for member level annotations (methods, fields and constructors)

Here is a sample part of the API:

The Annotation interface

All these methods in the Annotations reader class return an instance of the type org.codehaus.backport175.reader.Annotation.

This class has some useful methods like:

But most likely you want to cast the instance to the correct annotation type (interface).


Here is an example on how to read in the EJB 3 transaction annotation:


The Annotations reader class is highly optimized and currently gives you up to 5 times better performance than regular Java 5 reflective calls (e.g. MyClass.class.getAnnotation(..))

  • No labels