72 Annotation retention
CompileHint has source retention; CatalogHint has binary retention. Neither is returned by runtime annotation lookup. Binary metadata remains available to compiler and documentation tooling; runtime reflection requires RuntimeRetention.
norm
import std.annotation.TypeTarget
import std.annotation.SourceRetention
import std.annotation.BinaryRetention
annotation CompileHint implements TypeTarget, SourceRetention {}
annotation CatalogHint implements TypeTarget, BinaryRetention {}
@CompileHint()
@CatalogHint()
class Task {}
main() {
printLine(Task.class.annotation<CompileHint>() == null)
printLine(Task.class.annotation<CatalogHint>() == null)
}Expected output:
text
true
trueTry it: Change CatalogHint to RuntimeRetention and predict the second line.
Precise rules: Reference.