I think I don't quite understand annotations. I'd ...
# getting-started
y
I think I don't quite understand annotations. I'd like to make an annotation that validates that a function parameter has some property, and otherwise throws when the function is called. is this possible?
s
Annotations don't actually do anything on their own. They just let you tag up a piece of code with instructions or information that can be read by some other tool. That tool might be a compiler plugin or a runtime library that works using reflection. So what you're describing is possible, but you'd need an additional tool to actually perform the validation. There are some libraries available for that, but it depends what type of project you're working on.
y
I see! so this isn't quite like a macro which expands to some code, it just adds additional metadata.
👍 1
that's a clear explanation. much appreciated as always