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

15.1: Clarify that void expressions may be lambda bodies

XMLWordPrintable

      JLS 15.1 has always said: "An expression denotes nothing if and only if it is a method invocation (§15.12) that invokes a method that does not return a value, that is, a method declared void (§8.4). Such an expression can be used only as an expression statement (§14.8), because every other context in which an expression can appear requires the expression to denote something."

      The second sentence is wrong with the advent of lambda expressions. A lambda expression's body may contain a void expression without the void expression being used as an expression statement. The following lambda body has no semicolons, hence no expression statements, yet the void expression is legal as the body:

        x.m(e -> System.out.println("hi"));

            abuckley Alex Buckley
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: