Skip to content

71 注解目标 ​

Label 实现 TypeTarget,因此可标记类型声明。SourceRetention 让此注解在编译期间发挥作用,不提供运行时反射。

norm
import std.annotation.TypeTarget
import std.annotation.SourceRetention

annotation Label implements TypeTarget, SourceRetention {
  String text
}

@Label(text: "task")
class Task { String title }

main() {
  printLine(Task(title: "Learn Norm").title)
}

预期输出:

text
Learn Norm

动手试试:将 @Label 移到 main() 上,观察目标不匹配的诊断。

精确规则:参考。

Norm 0.25