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

Compiler does not accept generic method calls wrapped with parens

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2003

      Description

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

        Attachments

          Activity

            People

            • Assignee:
              jjg Jonathan Gibbons
              Reporter:
              ndcosta Nelson Dcosta
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: