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

Wrong Scope in Lambda Expressions Tutorial

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • 8, 9.0.1
    • docs
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      At the last paragraph of accessing local variables section, (right above the 'target typing' section), the doc says 'FirstLevel.x' is not effectively final anymore. But the assignment is done to the parameter. Also last sentence says 'myConsumer tries to access FirstLevel.x variable', this is wrong, it tries to access the parameter x.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the parameter x is not effectively final anymore
      and
      myConsumer tries to access parameter x
      ACTUAL -
      Because of this assignment statement, the variable FirstLevel.x is not effectively final anymore. As a result, the Java compiler generates an error message similar to "local variables referenced from a lambda expression must be final or effectively final" where the lambda expression myConsumer tries to access the FirstLevel.x variable:

      System.out.println("x = " + x);

      URL OF FAULTY DOCUMENTATION :
      https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#accessing-local-variables

            rgallard Raymond Gallardo
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: