Square brackets ([ ]) enclose a strongly typed annotation applied to a class, interface, enum, or a supported class member. A strongly typed annotation associates metadata, defined by a user‑defined annotation class, with the program element that immediately follows the annotation.

Annotations enclosed in square brackets are validated by the compiler against the corresponding annotation class definition and are stored in r-code. At runtime, the annotation metadata can be retrieved through the ABL reflection API as a read-only object of the annotation type with its property values populated.

Syntax

[annotation-name [ (
    [ property-name = constant [, property-name = constant ] ... ] ) ]]
annotation-name
The name of a user-defined annotation class. The annotation class must be defined using the ANNOTATION statement and be available on the PROPATH or specified using a USING statement.
property-name
The name of a property defined in the annotation class. Property names are not case-sensitive and must be unique within the annotation usage.
constant
A constant value compatible with the data type of the annotation property. Only constant values are allowed.

Example

The following example defines an annotation class and applies it to a method.

Annotation definition:

/* service/ResourceMapping.cls */
ANNOTATION service.ResourceMapping:
    DEFINE PUBLIC PROPERTY type      AS CHARACTER.
    DEFINE PUBLIC PROPERTY operation AS CHARACTER.
    DEFINE PUBLIC PROPERTY URI       AS CHARACTER.
    DEFINE PUBLIC PROPERTY alias     AS CHARACTER.
    DEFINE PUBLIC PROPERTY mediaType AS CHARACTER.
END ANNOTATION.

Annotation usage:


USING service.ResourceMapping FROM PROPATH.

CLASS com.sales.MyClass:
    [ResourceMapping(
        type       = "REST",
        operation  = "read",
        URI        = "?filter=~{filter~}",
        alias      = "",
        mediaType  = "application/json")
    ].
    METHOD PUBLIC VOID ReadTestBE(
        INPUT filter AS CHARACTER,
        OUTPUT DATASET dsTestBE):
    END METHOD.
END CLASS.

In this example, the ResourceMapping annotation is associated with the ReadTestBE() method. The compiler validates the property names and values and stores the annotation metadata in r-code for runtime access through reflection.

Notes

  • The annotation usage should appear on its own line, enclosed in square brackets, and precede the class or class member it annotates.
  • An annotation is associated with the next syntactic element encountered by the compiler, ignoring intervening comments and other annotations. Multiple annotations may apply to the same element, but the same annotation type cannot be repeated on that element.
  • You are not required to specify values for all properties defined in the annotation class. Properties not specified in the annotation usage retain their default or INITIAL values.
  • The order of property assignments in an annotation usage is not significant.
  • For marker annotations (annotation classes with no properties), the parentheses are optional:
    [Exportable].
    or
    [Exportable()].
  • Annotation values cannot be modified at runtime. Annotation metadata is retrieved via the ABL reflection API as a read‑only instance of the annotation type. This instance is created by the runtime on demand and cannot be instantiated directly by application code.
  • Strongly typed annotations (enclosed in [ ]) may be used alongside source-only annotations (@) in the same source file. Each follows its own syntax and rules.

See also

ANNOTATION statement, DEFINE PROPERTY statement, Progress.Lang.Annotation class, IsAnnotation( ) method, GetAnnotation( ) method, GetAnnotations( ) method, HasAnnotation( ) method