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

Collectors.counting can use Collectors.summingLong to reduce boxing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • None
    • core-libs
    • None

    Backports

      Description

        Collectors.counting is implemented as follows:

            public static <T> Collector<T, ?, Long>
            counting() {
                return reducing(0L, e -> 1L, Long::sum);
            }

        As Tagir states here:

        http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-September/035255.html

        That implementation results in much boxing.The implementation could use summingLong instead:

            public static <T> Collector<T, ?, Long>
            counting() {
                return summingLong(e -> 1L);
            }

        Attachments

          Issue Links

            Activity

              People

                psandoz Paul Sandoz
                psandoz Paul Sandoz
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: