Class AppliedOnClassAnnotationObject

All Implemented Interfaces:
Annotation

An implementation of an annotation that can be dynamically applied to classes, methods, fields, and constructors, with additional support for type-safe class targeting via the onClass() property.

This class extends AppliedAnnotationObject to provide both string-based targeting (via AppliedAnnotationObject.on()) and type-safe class-based targeting (via onClass()).

Difference between on and onClass:
  • AppliedAnnotationObject.on() - Returns string-based targets (e.g., "com.example.MyClass")
    Useful for:
    • Configuration files where class references aren't available
    • Targeting classes that may not be loaded yet
    • Pattern matching or wildcard targeting
  • onClass() - Returns Class object targets (e.g., MyClass.class)
    Useful for:
    • Type-safe programmatic configuration
    • Direct class references in code
    • Avoiding string-based name matching
Example:

// Using onClass() for type-safe targeting BeanAnnotation annotation = BeanAnnotation .create() .onClass(MyClass.class, MyOtherClass.class) .sort(true) .build(); // Using on() for string-based targeting BeanAnnotation annotation2 = BeanAnnotation .create() .on("com.example.MyClass", "com.example.MyOtherClass") .sort(true) .build(); // Can use both together BeanAnnotation annotation3 = BeanAnnotation .create() .on("com.example.MyClass") // String-based .onClass(MyOtherClass.class) // Type-safe .sort(true) .build();

Notes:
See Also: