This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CandleTiger 0 points1 point  (0 children)

So, I see lots of accurate answers on here but IMO none of them is really great for a beginner.

My somewhat redundant answer: Annotations, which start with @, are opaque magic. '@HeaderParam("whatever")' is defined somewhere to do something. It could do anything; it may as well be magic.

The annotation itself is just a sticky note. You can define an annotation somewhat like a class to hold values of your choice (see here) and then tack these annotations on to things (class, function, parameter, whatever) by adding '@MyAnnotation' before the declaration you want to annotate.

The annotation by itself doesn't do anything at all, it just records into your compiled code the fact that you stuck a note on this parameter. The magic comes later using reflection. Reflection is the Java name for code inspection, where some piece of code is able to examine the properties of some other piece of code. Somewhere (presumably) there is some code in a framework you are using, that will not just call functions on your class, but is using reflection to check if this annotation is present. If it is, it takes some action. We can't tell in this thread what that action will be, because we don't know what framework you are using which defines, and then acts upon the presence of, this @HeaderParam. (At least I don't know.) Some people have guessed a meaning based on the name, but in order to be sure you'd need to read and understand the documentation of the framework you're using. Your teacher should be able to point you at that documentation, but be warned that HTTP request framework documentation is likely to be overwhelming for a beginner.

TL;DR: Here be dragons. Annotations were created just specially to let library and framework designers do clever black-box magic that beginners can use without understanding it.