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

Confusing compilation error for lambda

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • tbd
    • 9
    • tools
    • b76
    • 9

      After JDK-8131742 was fixed the following code with syntax error won't compile any more:

      class A {
          static Runnable r = (__GAR BAGE__.this) -> { };
      }

      Compilation error:
      A.java:2: error: ',', ')', or '[' expected
          static Runnable r = (__GAR BAGE__.this) -> { };
                                           ^
      A.java:2: error: as of release 8, 'this' is allowed as the parameter name for the receiver type only, which has to be the first parameter
          static Runnable r = (__GAR BAGE__.this) -> { };
                                            ^
      A.java:2: error: ';' expected
          static Runnable r = (__GAR BAGE__.this) -> { };
                                                ^
      3 errors

      I believe the second message is confusing because receiver parameter is not allowed in FormalParameters of a lambda expression (JLS 15.27.1. Lambda Parameters) at all.

            mcimadamore Maurizio Cimadamore
            snikandrova Svetlana Nikandrova (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: