Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6481655

Parser confused by combination of parens and explicit type args

XMLWordPrintable

    • 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.

            mcimadamore Maurizio Cimadamore
            emcmanus Eamonn McManus
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: