Type annotations on inner type that is an array components
Werner Dietl
wdietl at gmail.com
Wed Jul 18 23:49:55 UTC 2018
Take this example:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@interface TA {
int value();
}
class ArrayOfInner {
class Inner {}
@TA(1) ArrayOfInner. @TA(2) Inner oi;
@TA(3) ArrayOfInner. @TA(4) Inner [] oia;
@TA(5) Inner i;
@TA(6) Inner [] ia;
}
Compile with javac 8 and according to javap -v field ia has the annotation:
ArrayOfInner$Inner[] ia;
descriptor: [LArrayOfInner$Inner;
flags: (0x0000)
RuntimeVisibleTypeAnnotations:
0: #10(#11=I#21): FIELD, location=[ARRAY, INNER_TYPE]
TA(
value=6
)
Compile with javac 9, 10, or a recent 11 build and ia has the annotation:
ArrayOfInner$Inner[] ia;
descriptor: [LArrayOfInner$Inner;
flags: (0x0000)
RuntimeVisibleTypeAnnotations:
0: #10(#11=I#21): FIELD, location=[ARRAY]
TA(
value=6
)
Note the missing INNER_TYPE location.
The annotations for fields oi, oia, and i are generated consistently
for all versions and are just included to illustrate all the relevant
annotation positions.
I would like to argue that the Java 8 behavior was correct.
I didn't find an existing issue that either motivated this change or
that would report this mismatch.
Thoughts?
cu, WMD.
--
http://www.google.com/profiles/wdietl
More information about the compiler-dev
mailing list