Another possible generics bug
Richard Warburton
richard.warburton at gmail.com
Mon Dec 5 14:36:39 PST 2011
>From http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.3.1:
"A declaration d of a type named n shadows the declarations of any other
types named n that are in scope at the point where d occurs throughout
the scope of d."
Which suggests to me that in the following example, the inner class T
should be the type of the field 'q'.
class Test<T> {
class T { }
T q;
public static void main(String[] args) throws Exception {
System.out.println(Test.class.getDeclaredField("q").getType());
}
}
This example compiles fine under both ecj and javac. In ecj Test.T is
picked as the type for q, in javac the generic parameter <T> is picked.
Is this a bug, or have I misread the specification?
I'm using the following version:
Javac version = 1.7.0_147
eclipse build number = 20110916-0149 (Indigo service release 1)
regards,
Richard
More information about the compiler-dev
mailing list