Another possible generics bug
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Dec 6 04:03:10 PST 2011
On 05/12/11 22:36, Richard Warburton wrote:
> class Test<T> {
> class T { }
> T q;
>
> public static void main(String[] args) throws Exception {
> System.out.println(Test.class.getDeclaredField("q").getType());
> }
>
> }
I think there's one underlying issue here - which is a difference in the
way shadowing for type-varables is handled in javac w.r.t. to Eclipse.
When two names are available, a class name and a type-variable name
respectively, javac seems to prefer the class name - this results in
your first bug - as a type-variable cannot be referenced from static
context, and in this reflection glitch.
I think some work as been done on this early in JDK 7 - see [1];
unfortunately the fix seems to be incomplete; it only addresses the very
specific issue raised in that very same bug report (shadowing within
type-variable declaration), and not the wider issue of scoping of
type-variables vs. class names.
Maurizio
[1] - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5060485
More information about the compiler-dev
mailing list