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

Collectors.counting can use Collectors.summingLong to reduce boxing

XMLWordPrintable

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

        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);
            }

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

                Created:
                Updated:
                Resolved: