-
Bug
-
Resolution: Fixed
-
P4
-
6, 6u23, 7
-
b27
-
generic, x86
-
generic, linux, windows_7
-
Not verified
Consider the following program, Util.java:
public class Util {
@SuppressWarnings("unchecked")
public static <T> T cast(Object x) {
return (T) x;
}
static {
Util.<Object>cast(null);
(Util.<Object>cast(null)).getClass();
}
}
The first statement in the static initializer compiles without problems. But the second statement produces the following error:
Util.java:9: illegal start of expression
(Util.<Object>cast(null)).getClass();
^
Various experiments show that it is the combination of the parentheses and the explicit type argument that provokes the problem.
public class Util {
@SuppressWarnings("unchecked")
public static <T> T cast(Object x) {
return (T) x;
}
static {
Util.<Object>cast(null);
(Util.<Object>cast(null)).getClass();
}
}
The first statement in the static initializer compiles without problems. But the second statement produces the following error:
Util.java:9: illegal start of expression
(Util.<Object>cast(null)).getClass();
^
Various experiments show that it is the combination of the parentheses and the explicit type argument that provokes the problem.
- duplicates
-
JDK-6998697 boolean expression deemed illegal - but only inside of an assertion
- Closed
-
JDK-7019649 Syntax error for ternary operator with a generic method call as second result
- Closed
- relates to
-
JDK-6665356 Cast not allowed when both qualifying type and inner class are parameterized
- Closed
-
JDK-6318240 Creation of array of inner class of an enclosing wildcard type doesn't work
- Closed