Class AppliedAnnotationObject

java.lang.Object
org.apache.juneau.commons.annotation.AnnotationObject
org.apache.juneau.commons.annotation.AppliedAnnotationObject
All Implemented Interfaces:
Annotation
Direct Known Subclasses:
AppliedOnClassAnnotationObject

An implementation of an annotation that can be dynamically applied to classes, methods, fields, and constructors at runtime.

This class extends AnnotationObject to provide support for annotations that have an on property which allows them to be targeted to specific program elements based on their fully-qualified names.

Overview:

Applied annotations allow you to define annotation properties in external configuration or programmatically at runtime, rather than requiring them to be declared directly on classes, methods, fields, or constructors at compile-time.

This is particularly useful for:

  • Configuration-driven behavior - Define annotation properties in config files without modifying source code
  • Dynamic application - Apply annotations to third-party classes where you can't modify the source
  • Runtime customization - Change annotation properties based on runtime conditions
  • Centralized configuration - Define annotation properties for multiple classes in one place
Targeting with on:

The base AppliedAnnotationObject.Builder.on(String...) method accepts fully-qualified names in the following formats:

  • "com.example.MyClass" - Target a specific class
  • "com.example.MyClass.myMethod" - Target a specific method
  • "com.example.MyClass.myField" - Target a specific field
  • "com.example.MyClass(java.lang.String,int)" - Target a specific constructor
Builder Variants:

This class provides specialized builder variants for different targeting scenarios:

Example:

// Create a Bean annotation that applies to MyClass BeanAnnotation annotation = BeanAnnotation .create(MyClass.class) .sort(true) .build(); // Or target by string name BeanAnnotation annotation2 = BeanAnnotation .create() .on("com.example.MyClass") .sort(true) .build();

Notes:
  • The on() method returns the string-based targets
  • Subclasses may provide additional onClass(), onMethod(), etc. methods for type-safe access
  • All builder methods return the builder for method chaining
  • Hashcode is calculated lazily on first access and then cached for performance
See Also:
  • Constructor Details

  • Method Details

    • on

      public String[] on()
      The targets this annotation applies to.
      Returns:
      The targets this annotation applies to.