-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b49
-
generic
-
solaris_8
Given the class declarations
class A<T> {
class B<U> {
X<T,U> x;
}
}
and the variables
A<String>.B<Integer> ab1;
A .B<Integer> ab2;
A<String>.B ab3;
A .B ab4
what are the types of
ab1.x
ab2.x
ab3.x
ab4.x
The answer is clear for ab1 and ab4 (X<String,Integer> and X,
respectively). But less clear for the others. javac definitely
doesn't do the right thing for these.
The draft JLS3 describes a simple and uniform rule to handle these
cases: a generic type without its type parameters is called a "raw"
type, and all of its nonstatic members are erased.
Given this rule, the type used to declare ab2 is illegal because the
inner class A.B isn't generic due to it being a nonstatic member of a
raw type.
Similarly, ab3 is raw. Therefore, its outer class should not be
given type parameters. Its declaration is illegal as well.
javac must implement these new rules.
Finally, there are some cases where javac fails to enforce a rule
from JLS (second edition) 8.5.2, which disallows referencing instance
members of an enclosing class from a static context. The failure of
javac to enforce that rule gets us into trouble in the presence of
generics. Here is an example of the problem:
class A<T> {
class B {
T t;
}
static class C {
B b;
// what is the type of b.t?
}
}
javac must implement this existing rule.
class A<T> {
class B<U> {
X<T,U> x;
}
}
and the variables
A<String>.B<Integer> ab1;
A .B<Integer> ab2;
A<String>.B ab3;
A .B ab4
what are the types of
ab1.x
ab2.x
ab3.x
ab4.x
The answer is clear for ab1 and ab4 (X<String,Integer> and X,
respectively). But less clear for the others. javac definitely
doesn't do the right thing for these.
The draft JLS3 describes a simple and uniform rule to handle these
cases: a generic type without its type parameters is called a "raw"
type, and all of its nonstatic members are erased.
Given this rule, the type used to declare ab2 is illegal because the
inner class A.B isn't generic due to it being a nonstatic member of a
raw type.
Similarly, ab3 is raw. Therefore, its outer class should not be
given type parameters. Its declaration is illegal as well.
javac must implement these new rules.
Finally, there are some cases where javac fails to enforce a rule
from JLS (second edition) 8.5.2, which disallows referencing instance
members of an enclosing class from a static context. The failure of
javac to enforce that rule gets us into trouble in the presence of
generics. Here is an example of the problem:
class A<T> {
class B {
T t;
}
static class C {
B b;
// what is the type of b.t?
}
}
javac must implement this existing rule.
- duplicates
-
JDK-4881416 generics: use of inner raw class causes verify error
-
- Closed
-