[JSR308] Annotations in initialization code
Brian.Campbell at ed.ac.uk
Tue Aug 18 10:06:52 EDT 2009
We've recently been using type annotations at object creation and consulting
them while processing the corresponding bytecode. Most of the time this has
been working fine, but we were rather surprised to see that annotations for
field initialization and instance initializers outside of a constructor are
placed on the field or enclosing class, rather than on the <init> method.
While this is consistent with the spec, it makes finding the possible
annotations corresponding to a bytecode instruction in an initializer method
a little difficult. If I understand correctly, if
1) you are dealing with an <init> method, and
2) it does not call another <init> method in the same class,
then you must look at the annotations for all of the fields and the class
in addition to the method's annotations.
Is this a correct interpretation, or is there a simpler way?
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
More information about the JSR308