[type-annos-observers] Question regarding j.l.Class.getAnnotatedInterfaces()
elena votchennikova
elena.votchennikova at oracle.com
Tue Jul 23 08:31:40 PDT 2013
Hello,
Could you please help me with understanding of the
j.l.Class.getAnnotatedInterfaces() method behavior and specification?
From the API spec (for jdk8b99):
"Returns an array of AnnotatedType objects that represent the use of
types to specify superinterfaces of the entity represented by this
Class." ... "If this Class represents a class or interface whose
declaration does not explicitly indicate any annotated superinterfaces,
the return value is an array of length 0."
Lets look at the example.
We have to classes Cls1 and Cls2 that implement the same interfaces
Interf1 and Interf2.
But in first case the use of these types are annotated and in second
case - not:
class Cls1 implements @Anno Interf1, @Anno Interf2 {}
class Cls2 implements Interf1, Interf2 {}
For Cls1:
Cls1.class.getAnnotatedInterfaces() will return an array of two
AnnotatedType objects that represent Interf1 and Interf2 classes.
For Cls2:
Cls2.class.getAnnotatedInterfaces() should return an empty array if
Interf1 and Interf2 declarations are not directly annotated, shouldn't it?
If Interf1 and Interf2 declarations are directly annotated this method
should return an array of AnnotatedType objects that represent these
interfaces (corresponding to the specification).
Is my understanding correct?
Lets look at the one more example:
class Cls3 implements Interf1, @Anno Interf2 {}
What will return method Cls3.class.getAnnotatedInterfaces()? And Why?
Thanks a lot,
Elena
More information about the type-annotations-spec-observers
mailing list