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

Compiler does not accept generic method calls wrapped with parens

XMLWordPrintable

    • x86
    • windows_2003

      FULL PRODUCT VERSION :
      1.6.0

      A DESCRIPTION OF THE PROBLEM :
      The javac compiler reports an "illegal start of expression" error when trying to compile:

      Object o = (Collections.<String>emptyList()).toString();

      However, it accepts the non-generic version:

      Object o = (Collections.emptyList()).toString();

      It seems to be a problem with explicitly passing the type parameter to the generic method, and wrapping the method invocation expression with parentheses.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try compiling the included source code.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The compilation should succeed.
      ACTUAL -
      d:\home\TestExplicitGenericDecl.java:9: illegal start of expression
              Object o = (a.<Object>id("foo")).toString();
                            ^
      d:\home\TestExplicitGenericDecl.java:10: illegal start of expression
              Object o2 = (Collections.<String>emptyList()).toString();
                                       ^
      2 errors

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;

      public class TestExplicitGenericDecl {

          private <T> T id(T x) { return x; }

          public static void main(String[] args) {
              TestExplicitGenericDecl a = new TestExplicitGenericDecl();
              Object o = (a.<Object>id("foo")).toString();
              Object o2 = (Collections.<String>emptyList()).toString();
          }
      }

      ---------- END SOURCE ----------

            jjg Jonathan Gibbons
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: