Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • or you define aliases (shortcuts/abbreviations), for the annotations and map these to the fully qualified class names for the annotation interfaces. This is done using the annotations.properties file.
    Example:
    Code Block
    java
    java
    OneWay = org.codehaus.backport175.annotation.OneWay
    TwoWay = org.codehaus.backport175.annotation.TwoWay
    
    If we now feed this property file to the compiler we are able to write the annotations like this instead:
    Code Block
    java
    java
    /**
     * @OneWay
     */
    public void method() {
        ...
    }
    

The choice is yours, we are just providing an option to the FQN way of writing.

Rules for annotation naming consistency

It is important to remember that if you are using an alias through a propery file, the annotation name is still the fully qualified name of the interface class for the annotation when using the Annotations.getAnnotation API.

If you decide to use an alias, then you have to use this alias in the whole sources. It is not possible to use from time to time in the source an alias or the fully qualified name, since backport175 has to ensure an element cannot be annotated twice with the same annotation, as per JSR-175.
If you decide to use the fully qualified name, the same rule applies, it needs to stay consistent.

If the annotation is a nested class like Target.OneWay below, you can use a $ in the name (as when using java.lang.reflect.* API) or a . which can be more readable.
Once again, this choice has to be consistent thus one or the other has to be used accross the code base but not both:

Code Block
java
java

package demo;
/**
 * @demo.Target$OneWay
 */
public class Target {
  public static class OneWay {}
}

or (with dot)

Code Block
java
java

package demo;
/**
 * @demo.Target.OneWay
 */
public class Target {
  public static class OneWay {}
}