What is the syntax for annotation type elements?
How do I read/understand the following statement in Java?
Class<?> groups() default {};
Class < ? extends Payload> payload() default {};
I think I can understand them individually but I don't know if I get good sense of what it means in its entirety.
Individually:
Class<?>
means any class andClass< ? extends Payload>
means any class that extends thePayload
class
[ ]
seems to refer to any array of classes. Is that correct?
groups()
andpayload()
are method names.
default{}
Use this when there is no implementation?
I am really not sure how to understand the above statements? Any help would be very much appreciated.
java
add a comment |
How do I read/understand the following statement in Java?
Class<?> groups() default {};
Class < ? extends Payload> payload() default {};
I think I can understand them individually but I don't know if I get good sense of what it means in its entirety.
Individually:
Class<?>
means any class andClass< ? extends Payload>
means any class that extends thePayload
class
[ ]
seems to refer to any array of classes. Is that correct?
groups()
andpayload()
are method names.
default{}
Use this when there is no implementation?
I am really not sure how to understand the above statements? Any help would be very much appreciated.
java
This code is from an annotation, isn't?
– user10639668
Nov 22 at 18:14
Yes..I came across it when working on developing a validator. This is used in the validator annotation interface
– Aaron
Nov 22 at 18:16
2
Please familiarize yourself with StackOverflows editor. Using code formatting and syntax highlighting would greatly help boosting the quality of your question :)
– Zabuza
Nov 22 at 18:17
add a comment |
How do I read/understand the following statement in Java?
Class<?> groups() default {};
Class < ? extends Payload> payload() default {};
I think I can understand them individually but I don't know if I get good sense of what it means in its entirety.
Individually:
Class<?>
means any class andClass< ? extends Payload>
means any class that extends thePayload
class
[ ]
seems to refer to any array of classes. Is that correct?
groups()
andpayload()
are method names.
default{}
Use this when there is no implementation?
I am really not sure how to understand the above statements? Any help would be very much appreciated.
java
How do I read/understand the following statement in Java?
Class<?> groups() default {};
Class < ? extends Payload> payload() default {};
I think I can understand them individually but I don't know if I get good sense of what it means in its entirety.
Individually:
Class<?>
means any class andClass< ? extends Payload>
means any class that extends thePayload
class
[ ]
seems to refer to any array of classes. Is that correct?
groups()
andpayload()
are method names.
default{}
Use this when there is no implementation?
I am really not sure how to understand the above statements? Any help would be very much appreciated.
java
java
edited Nov 22 at 18:37
Sotirios Delimanolis
207k39476568
207k39476568
asked Nov 22 at 18:09
Aaron
333
333
This code is from an annotation, isn't?
– user10639668
Nov 22 at 18:14
Yes..I came across it when working on developing a validator. This is used in the validator annotation interface
– Aaron
Nov 22 at 18:16
2
Please familiarize yourself with StackOverflows editor. Using code formatting and syntax highlighting would greatly help boosting the quality of your question :)
– Zabuza
Nov 22 at 18:17
add a comment |
This code is from an annotation, isn't?
– user10639668
Nov 22 at 18:14
Yes..I came across it when working on developing a validator. This is used in the validator annotation interface
– Aaron
Nov 22 at 18:16
2
Please familiarize yourself with StackOverflows editor. Using code formatting and syntax highlighting would greatly help boosting the quality of your question :)
– Zabuza
Nov 22 at 18:17
This code is from an annotation, isn't?
– user10639668
Nov 22 at 18:14
This code is from an annotation, isn't?
– user10639668
Nov 22 at 18:14
Yes..I came across it when working on developing a validator. This is used in the validator annotation interface
– Aaron
Nov 22 at 18:16
Yes..I came across it when working on developing a validator. This is used in the validator annotation interface
– Aaron
Nov 22 at 18:16
2
2
Please familiarize yourself with StackOverflows editor. Using code formatting and syntax highlighting would greatly help boosting the quality of your question :)
– Zabuza
Nov 22 at 18:17
Please familiarize yourself with StackOverflows editor. Using code formatting and syntax highlighting would greatly help boosting the quality of your question :)
– Zabuza
Nov 22 at 18:17
add a comment |
1 Answer
1
active
oldest
votes
default {} --> Use this when there is no implementation?
In an Annotation definition you can specify a default value for a parameter. The {}
after default is an array literal for an empty array. You could also set it to some non empty value. This also works for other objects too. eg the Data
annotation from lombok where a default string is declared:
public @interface Data {
String staticConstructor() default "";
}
Class means any class and "Class< ? extends Payload>" means any class
that extends the Payload class
Yes
[ ] --> Seems to refer to any array of classes. Is that correct?
Yes
groups() and payload() are method names.
They are the name of the parameter used in annotation declaration, as well as the name of the getter methods for those values. eg you could define:
@Data(staticConstructor = "of") class Foobar {}
And later you could get the value by using the getter method created:
Data dataAnnotation = Foobar.class.getAnnotation(Data.class);
String staticConstructor = dataAnnotation.staticConstructor();
Note that you will not actually be able to retrieve the value for an annotation in runtime unless the annotation definition is also annotated with @Retention(RetentionPolicy.RUNTIME)
1
Thank you so much. This helped with clarifying my thoughts.
– Aaron
Dec 5 at 18:16
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436286%2fwhat-is-the-syntax-for-annotation-type-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
default {} --> Use this when there is no implementation?
In an Annotation definition you can specify a default value for a parameter. The {}
after default is an array literal for an empty array. You could also set it to some non empty value. This also works for other objects too. eg the Data
annotation from lombok where a default string is declared:
public @interface Data {
String staticConstructor() default "";
}
Class means any class and "Class< ? extends Payload>" means any class
that extends the Payload class
Yes
[ ] --> Seems to refer to any array of classes. Is that correct?
Yes
groups() and payload() are method names.
They are the name of the parameter used in annotation declaration, as well as the name of the getter methods for those values. eg you could define:
@Data(staticConstructor = "of") class Foobar {}
And later you could get the value by using the getter method created:
Data dataAnnotation = Foobar.class.getAnnotation(Data.class);
String staticConstructor = dataAnnotation.staticConstructor();
Note that you will not actually be able to retrieve the value for an annotation in runtime unless the annotation definition is also annotated with @Retention(RetentionPolicy.RUNTIME)
1
Thank you so much. This helped with clarifying my thoughts.
– Aaron
Dec 5 at 18:16
add a comment |
default {} --> Use this when there is no implementation?
In an Annotation definition you can specify a default value for a parameter. The {}
after default is an array literal for an empty array. You could also set it to some non empty value. This also works for other objects too. eg the Data
annotation from lombok where a default string is declared:
public @interface Data {
String staticConstructor() default "";
}
Class means any class and "Class< ? extends Payload>" means any class
that extends the Payload class
Yes
[ ] --> Seems to refer to any array of classes. Is that correct?
Yes
groups() and payload() are method names.
They are the name of the parameter used in annotation declaration, as well as the name of the getter methods for those values. eg you could define:
@Data(staticConstructor = "of") class Foobar {}
And later you could get the value by using the getter method created:
Data dataAnnotation = Foobar.class.getAnnotation(Data.class);
String staticConstructor = dataAnnotation.staticConstructor();
Note that you will not actually be able to retrieve the value for an annotation in runtime unless the annotation definition is also annotated with @Retention(RetentionPolicy.RUNTIME)
1
Thank you so much. This helped with clarifying my thoughts.
– Aaron
Dec 5 at 18:16
add a comment |
default {} --> Use this when there is no implementation?
In an Annotation definition you can specify a default value for a parameter. The {}
after default is an array literal for an empty array. You could also set it to some non empty value. This also works for other objects too. eg the Data
annotation from lombok where a default string is declared:
public @interface Data {
String staticConstructor() default "";
}
Class means any class and "Class< ? extends Payload>" means any class
that extends the Payload class
Yes
[ ] --> Seems to refer to any array of classes. Is that correct?
Yes
groups() and payload() are method names.
They are the name of the parameter used in annotation declaration, as well as the name of the getter methods for those values. eg you could define:
@Data(staticConstructor = "of") class Foobar {}
And later you could get the value by using the getter method created:
Data dataAnnotation = Foobar.class.getAnnotation(Data.class);
String staticConstructor = dataAnnotation.staticConstructor();
Note that you will not actually be able to retrieve the value for an annotation in runtime unless the annotation definition is also annotated with @Retention(RetentionPolicy.RUNTIME)
default {} --> Use this when there is no implementation?
In an Annotation definition you can specify a default value for a parameter. The {}
after default is an array literal for an empty array. You could also set it to some non empty value. This also works for other objects too. eg the Data
annotation from lombok where a default string is declared:
public @interface Data {
String staticConstructor() default "";
}
Class means any class and "Class< ? extends Payload>" means any class
that extends the Payload class
Yes
[ ] --> Seems to refer to any array of classes. Is that correct?
Yes
groups() and payload() are method names.
They are the name of the parameter used in annotation declaration, as well as the name of the getter methods for those values. eg you could define:
@Data(staticConstructor = "of") class Foobar {}
And later you could get the value by using the getter method created:
Data dataAnnotation = Foobar.class.getAnnotation(Data.class);
String staticConstructor = dataAnnotation.staticConstructor();
Note that you will not actually be able to retrieve the value for an annotation in runtime unless the annotation definition is also annotated with @Retention(RetentionPolicy.RUNTIME)
edited Nov 22 at 18:44
answered Nov 22 at 18:27
flakes
6,51611850
6,51611850
1
Thank you so much. This helped with clarifying my thoughts.
– Aaron
Dec 5 at 18:16
add a comment |
1
Thank you so much. This helped with clarifying my thoughts.
– Aaron
Dec 5 at 18:16
1
1
Thank you so much. This helped with clarifying my thoughts.
– Aaron
Dec 5 at 18:16
Thank you so much. This helped with clarifying my thoughts.
– Aaron
Dec 5 at 18:16
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436286%2fwhat-is-the-syntax-for-annotation-type-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This code is from an annotation, isn't?
– user10639668
Nov 22 at 18:14
Yes..I came across it when working on developing a validator. This is used in the validator annotation interface
– Aaron
Nov 22 at 18:16
2
Please familiarize yourself with StackOverflows editor. Using code formatting and syntax highlighting would greatly help boosting the quality of your question :)
– Zabuza
Nov 22 at 18:17