V
Vidar S. Ramdal
I've started playing around with annotations.
I'm trying to find out, runtime, if a given method has an annotation:
@java.lang.annotation.Target(value =
java.lang.annotation.ElementType.METHOD)
@java.lang.annotation.Retention(value =
java.lang.annotation.RetentionPolicy.RUNTIME)
public @interface RestrictedAccess {
...
}
And the method:
@RestrictedAccess public void methodName() {
...
}
Now I want to find the @RestrictedAccess annotation runtime. I have a
reference to the method from reflection:
RestrictedAccess restriction = method.getAnnotation(RestrictedAccess.class);
However, 'restriction' allways turns out as null. When I inspect the
'method' object, I can see three arrays (annotations,
parameterAnnotations, declaredAnnotations), which all are null.
I thought specifying RetentionPolicy.RUNTIME would assure that the
annotation would be available runtime, but no luck.
What's going on here?
I'm trying to find out, runtime, if a given method has an annotation:
@java.lang.annotation.Target(value =
java.lang.annotation.ElementType.METHOD)
@java.lang.annotation.Retention(value =
java.lang.annotation.RetentionPolicy.RUNTIME)
public @interface RestrictedAccess {
...
}
And the method:
@RestrictedAccess public void methodName() {
...
}
Now I want to find the @RestrictedAccess annotation runtime. I have a
reference to the method from reflection:
RestrictedAccess restriction = method.getAnnotation(RestrictedAccess.class);
However, 'restriction' allways turns out as null. When I inspect the
'method' object, I can see three arrays (annotations,
parameterAnnotations, declaredAnnotations), which all are null.
I thought specifying RetentionPolicy.RUNTIME would assure that the
annotation would be available runtime, but no luck.
What's going on here?