java - Representation of inner source-retained annotation -
we have class:
public class myclass { @retention(retentionpolicy.source) private @interface myinterface { } @myinterface public void hello() { } }
as can see, has inner, source-only annotation. question is: should exported binary (jar) contain myclass$myinterface.class
file or not? if @ retention, can not, because annotation should discarded compiler. still added list of inner classes in myclass.class
, , myclass$myinterface.class
file created.
when run an annotation processor against class
public class myprocessedclass extends myclass {}
the annotation processing fails if call
myclass.getenclosedelements()
and myclass$myinterface.class
not present. processing ok, if myclass$myinterface.class
present.
my question is: should exported binary (jar) contain
myclass$myinterface.class
file or not?
it should.
- every class must contain symbolic references of member types, , local , anonymous classes appear in methods, constructors, static initializers, instance initializers, , field initializers.
4.7.6. innerclasses
attribute:
if class or interface has members classes or interfaces,
constant_pool
table (and henceinnerclasses
attribute) must refer each such member, if member not otherwise mentioned class.
so myclass
must have reference myinterface
. , although don't have citation this, seem if there references particular class, class should compiled.
Comments
Post a Comment