Custom Annotations
Annotations attach structured metadata to declarations that can be read at runtime through reflection. Cangjie defines annotation classes by marking them with @Annotation, and annotation classes must provide a const init constructor.
When defining an annotation, use @Annotation to decorate the class and declare the fields to be stored in the class. Annotation classes cannot be decorated with abstract, open, or sealed. When using annotations, the syntax is @AnnotationName[arguments], where arguments are evaluated at compile time and bound to the type.
Through TypeInfo.findAnnotation<T>(), you can retrieve annotation information on a type at runtime, which returns an Option<T> type. This allows frameworks to execute different logic at runtime based on annotations, such as version control, permission checking, etc.
The code on the right defines a @Version annotation and uses it to mark two API classes. At runtime, version numbers are read and printed through reflection.
Try adding a new annotation type, such as @Author to record author information.