A question about Depth of container annotations
deven you
youdwei at linux.vnet.ibm.com
Tue Jun 24 08:21:22 UTC 2014
Hi All,
I have a question about repeated annotation depth. If this is not the
proper mailing list group, please tell me where I should send it to.
My question will be about the depth of container annotations. For instance,
assume there are 3 annotations.
- RepeatedAnn
- ContainerAnn
- ContainerContainerAnn
So, ContainerContainerAnn can have ContainerAnn and that can also have
RepeatbleAnn in it.
In this case, get*AnnotationsByType(RepeatableAnn) APIs wont return
repeteableAnns in depth 2.
Java docs don't talk about the depth. I wonder if the get*AnnotationsByType
api should return the annotations of all depth?
If we have below annotations:
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(ContainerAnn.class)
@interface RepeatableAnn { String value(); }
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(ContainerContainerAnn.class)
@interface ContainerAnn { RepeatableAnn[] value(); }
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@interface ContainerContainerAnn { ContainerAnn[] value(); }
And the main class is annotated by :
@ContainerAnn({@RepeatableAnn("Parent-3")})
@ContainerAnn({@RepeatableAnn("Parent-4")})
public class Test { ...
when we call getAnnotationsByType(RepeatableAnn.class) on this class, we
get nothing because RepeatableAnn is contained by ContainerAnn which is
also contained by ContainerContainerAnn. In other words, RepeatableAnn is
in depth 2 and get*AnnotationsByType APIs only searches depth 1. The test
results are:
/home/deven/jdk8_20/jdk1.8.0_20/bin$ java repeated.Test
CLASS = repeated.Test
getDeclaredAnnotationsByType(RepeatableAnn.class)
getDeclaredAnnotationsByType(ContainerAnn.class)
@repeated.ContainerAnn(value=[@repeated.RepeatableAnn(value=Parent-3)])
@repeated.ContainerAnn(value=[@repeated.RepeatableAnn(value=Parent-4)])
getDeclaredAnnotationsByType(ContainerContainerAnn.class)
@repeated.ContainerContainerAnn(value=[@repeated.ContainerAnn(value=[@repeated.RepeatableAnn(value=Parent-3)]),
@repeated.ContainerAnn(value=[@repeated.RepeatableAnn(value=Parent-4)])])
getAnnotationsByType(RepeatableAnn.class)
getAnnotationsByType(ContainerAnn.class)
@repeated.ContainerAnn(value=[@repeated.RepeatableAnn(value=Parent-3)])
@repeated.ContainerAnn(value=[@repeated.RepeatableAnn(value=Parent-4)])
getAnnotationsByType(ContainerContainerAnn.class)
@repeated.ContainerContainerAnn(value=[@repeated.ContainerAnn(value=[@repeated.RepeatableAnn(value=Parent-3)]),
@repeated.ContainerAnn(value=[@repeated.RepeatableAnn(value=Parent-4)])])
More information about the core-libs-dev
mailing list