-
Bug
-
Resolution: Fixed
-
P5
-
6
-
None
-
rc
-
generic
-
generic
-
Verified
Oops. I think we just didn't think of this. It would be a shame for both to be illegal, as that would force folks to use raw types. I think javac's behavior is what we intended to specify. Section 4.5.2 failed to take into consideration that sometimes generic types are used in a context where performing a capture conversion is inappropriate. The definition of a "Reifiable Type" failed to consider inner classes too. I suspect there are other places in the spec that nested types are not properly handled.
-Neal
On 12/7/06, ... wrote:
javac accepts this case:
class X<T> {
class Y<T> {}
}
class B {
void f() {
X<B>.Y<B> xy = null;
boolean b2 = (xy instanceof X<?>.Y<?>);
}
}
But rejects this one:
class X<T> {
class Y<T> {}
}
class B {
void f() {
X<B>.Y<B> xy = null;
boolean b2 = (xy instanceof X<B>.Y<?>);
}
}
with the error:
t6.java:14: illegal generic type for instanceof
boolean b2 = (xy instanceof X<B>.Y<?>);
^
This seems to be treating X<?>.Y<?> as a type with only unbounded wildcards, but that is not how I read the JLS.
- 4.5.2 says that the members of wildcarded types are undefined, so we know that the parent class of Y<?> is not a wildcard.
- As far as I can tell, the X<?> in that context is replaced with its capture conversion.
So I would expect an error on both of these cases. What am I missing?
This comment was invalid and has been deleted
-Neal
On 12/7/06, ... wrote:
javac accepts this case:
class X<T> {
class Y<T> {}
}
class B {
void f() {
X<B>.Y<B> xy = null;
boolean b2 = (xy instanceof X<?>.Y<?>);
}
}
But rejects this one:
class X<T> {
class Y<T> {}
}
class B {
void f() {
X<B>.Y<B> xy = null;
boolean b2 = (xy instanceof X<B>.Y<?>);
}
}
with the error:
t6.java:14: illegal generic type for instanceof
boolean b2 = (xy instanceof X<B>.Y<?>);
^
This seems to be treating X<?>.Y<?> as a type with only unbounded wildcards, but that is not how I read the JLS.
- 4.5.2 says that the members of wildcarded types are undefined, so we know that the parent class of Y<?> is not a wildcard.
- As far as I can tell, the X<?> in that context is replaced with its capture conversion.
So I would expect an error on both of these cases. What am I missing?
This comment was invalid and has been deleted
- relates to
-
JDK-6486430 Compiler fails to reject access to static member in parameterized type
-
- Closed
-
-
JDK-6667132 Cast to partially raw type(rare type) should not be allowed
-
- Closed
-
-
JDK-4922142 generic enclosing type in cast: allowed?
-
- Closed
-