references to non-static types from annotations

Liam Miller-Cushon cushon at
Wed Apr 13 17:37:50 UTC 2016

On Wed, Apr 13, 2016 at 10:15 AM, Alex Buckley <alex.buckley at>

> To clarify, JLS 9.7.1 does not prohibit an annotation element in a static
> context from referring to a non-static class. I don't see why such a
> prohibition would be necessary, yet it sounds like you want javac to reject
> @A(I.class).
> The emission of an invalid return descriptor for class_info_index is
> "just" a javac issue, due to not erasing the fully qualified generic type
> of I. If the class literal does the erasure itself -- @A(Test.I.class)
> interface C {} -- then the program compiles and runs without error.

Thanks for clarifying. I assumed it was supposed to be consistent with
other expressions in static contexts. Is it correct that the following is
currently rejected?

class Test<T> {
  class I {}
  static final Class<?> C = I.class;

error: non-static class Test.I cannot be referenced from a static context
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list