M
M
missisli2017-02-19 22:33:12
Java
missisli, 2017-02-19 22:33:12

Why are arguments passed to the annotation in this way?

I'm sorry for the stupid question, but I'm really new to programming. While studying Java annotations, I came across the following code:

@Version(version = 42)
public class MyClass {}

public @interface Version {
    int version();
}

I have not seen anywhere before that arguments are passed in this way. Are they named parameters? Can it be used in your code? Also, why are fields declared like functions? Probably a stupid question, but I just don't know how to google it.
Thanks for your reply.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maks Burkov, 2017-02-21
@Maks00088

This thing is called annotations, used very heavily in J2EE! For a good understanding, I advise you to create a small project using annotations as markers or as mathematical data for any calculations. For example, write your bean validator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question