Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
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.
|