javac is not accepting correct code

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 22
    • Affects Version/s: 22
    • Component/s: tools
    • None
    • b27

      This code is failing to compile:

      import java.util.*;
      import java.util.function.*;

      class Test {
          public interface X {
              Object O = new Object() {
                  Function<String, String> x(Map<String, String> m) {
                      // Error: local variables referenced from a lambda expression must be final or effectively final
                      return s -> m.get(s);
                  }
              };
          }
      }

      reported by Paul Sandoz

            Assignee:
            Vicente Arturo Romero Zaldivar
            Reporter:
            Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: