Problems with ElementType.TYPE_USE and reflection

Kasper Nielsen kasperni at
Tue Nov 6 18:48:01 UTC 2018


I'm trying to understand exactly how ElementType.TYPE_USE should work.

I'm asking because the following program only prints that s has one 2
I believe it should either print 3 or be flagged at compilation time.

public class TestClass {

    String s;

    public static void main(String[] args) throws Exception {


    @interface X {}

    @interface Y {}

    @Target({ ElementType.FIELD, ElementType.TYPE_USE })
    @interface Z {}

ElementType.TYPE_USE alone isn't enough for the annotation information to
be retained at runtime.


More information about the core-libs-dev mailing list