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

The JavaDoc of java.util.stream.Collectors method collectingAndThen has incorrect code snippet

XMLWordPrintable

    • b143
    • Not verified

      A DESCRIPTION OF THE PROBLEM :
      Available code snippet is the following:
      List<String> people
               = people.stream().collect(collectingAndThen(toList(), Collections::unmodifiableList));

      But this is a compiler error: "the variable 'people' is already defined in the scope"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I think it should be written something like this:

      List<String> people
               = peopleList.stream().collect(collectingAndThen(toList(), Collections::unmodifiableList));
      ACTUAL -
      List<String> people
               = people.stream().collect(collectingAndThen(toList(), Collections::unmodifiableList));

      URL OF FAULTY DOCUMENTATION :
      https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html#collectingAndThen-java.util.stream.Collector-java.util.function.Function-

            psandoz Paul Sandoz
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: