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

Improve error message for '_' used as a lambda parameter name

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 8
    • tools
    • b112

    Description

      The parameter name '_' is prohibited by the parser for lambdas. This is correct behavior, but the error message is very unhelpful:

      UnderscoreName.java:7: error: <identifier> expected
        java.util.function.Function<String,String> f = _ -> "x";
                                                       ^
      UnderscoreName.java:7: error: illegal start of expression
        java.util.function.Function<String,String> f = _ -> "x";
                                                         ^
      UnderscoreName.java:7: error: ';' expected
        java.util.function.Function<String,String> f = _ -> "x";
                                                           ^
      A better approach would be to parse the name as is, and provide a descriptive error message in a later phase.

      Attachments

        Activity

          People

            vromero Vicente Arturo Romero Zaldivar
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: