Configuring Annotations to be RUNTIME Retention By Default (without individual @Retention)
up vote
0
down vote
favorite
Is it possible to have a configuration where all Annotations of a given name or type are automatically RetentionPolicy.RUNTIME
?
I came across a poblem where I need to use reflection at runtime to search for certain Annotations. But those are common Annotations scattered all over the app, such as @Service
or @Transactional
, and I can't go one by one and add @RetentionPolicy
to each one, it would be too long.
java annotations
add a comment |
up vote
0
down vote
favorite
Is it possible to have a configuration where all Annotations of a given name or type are automatically RetentionPolicy.RUNTIME
?
I came across a poblem where I need to use reflection at runtime to search for certain Annotations. But those are common Annotations scattered all over the app, such as @Service
or @Transactional
, and I can't go one by one and add @RetentionPolicy
to each one, it would be too long.
java annotations
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Is it possible to have a configuration where all Annotations of a given name or type are automatically RetentionPolicy.RUNTIME
?
I came across a poblem where I need to use reflection at runtime to search for certain Annotations. But those are common Annotations scattered all over the app, such as @Service
or @Transactional
, and I can't go one by one and add @RetentionPolicy
to each one, it would be too long.
java annotations
Is it possible to have a configuration where all Annotations of a given name or type are automatically RetentionPolicy.RUNTIME
?
I came across a poblem where I need to use reflection at runtime to search for certain Annotations. But those are common Annotations scattered all over the app, such as @Service
or @Transactional
, and I can't go one by one and add @RetentionPolicy
to each one, it would be too long.
java annotations
java annotations
asked yesterday
gene b.
1,57652454
1,57652454
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The Java Language Specification, section 9.6.4.2. @Retention states:
If T does not have a (meta-)annotation
m
that corresponds tojava.lang.annotation.Retention
, then a Java compiler must treat T as if it does have such a meta-annotationm
with an element whose value isjava.lang.annotation.RetentionPolicy.CLASS
.
As you can see, it is a strict requirement that missing annotation is same as @Retention(RetentionPolicy.CLASS)
.
If you need @Retention(RetentionPolicy.RUNTIME)
, then you must explicitly specify that.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The Java Language Specification, section 9.6.4.2. @Retention states:
If T does not have a (meta-)annotation
m
that corresponds tojava.lang.annotation.Retention
, then a Java compiler must treat T as if it does have such a meta-annotationm
with an element whose value isjava.lang.annotation.RetentionPolicy.CLASS
.
As you can see, it is a strict requirement that missing annotation is same as @Retention(RetentionPolicy.CLASS)
.
If you need @Retention(RetentionPolicy.RUNTIME)
, then you must explicitly specify that.
add a comment |
up vote
1
down vote
accepted
The Java Language Specification, section 9.6.4.2. @Retention states:
If T does not have a (meta-)annotation
m
that corresponds tojava.lang.annotation.Retention
, then a Java compiler must treat T as if it does have such a meta-annotationm
with an element whose value isjava.lang.annotation.RetentionPolicy.CLASS
.
As you can see, it is a strict requirement that missing annotation is same as @Retention(RetentionPolicy.CLASS)
.
If you need @Retention(RetentionPolicy.RUNTIME)
, then you must explicitly specify that.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The Java Language Specification, section 9.6.4.2. @Retention states:
If T does not have a (meta-)annotation
m
that corresponds tojava.lang.annotation.Retention
, then a Java compiler must treat T as if it does have such a meta-annotationm
with an element whose value isjava.lang.annotation.RetentionPolicy.CLASS
.
As you can see, it is a strict requirement that missing annotation is same as @Retention(RetentionPolicy.CLASS)
.
If you need @Retention(RetentionPolicy.RUNTIME)
, then you must explicitly specify that.
The Java Language Specification, section 9.6.4.2. @Retention states:
If T does not have a (meta-)annotation
m
that corresponds tojava.lang.annotation.Retention
, then a Java compiler must treat T as if it does have such a meta-annotationm
with an element whose value isjava.lang.annotation.RetentionPolicy.CLASS
.
As you can see, it is a strict requirement that missing annotation is same as @Retention(RetentionPolicy.CLASS)
.
If you need @Retention(RetentionPolicy.RUNTIME)
, then you must explicitly specify that.
answered yesterday
Andreas
73.3k456118
73.3k456118
add a comment |
add a comment |
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%2f53416981%2fconfiguring-annotations-to-be-runtime-retention-by-default-without-individual%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