Collectors.counting can use Collectors.summingLong to reduce boxing

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 9
    • Affects Version/s: None
    • Component/s: 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);
            }

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

                Created:
                Updated:
                Resolved: