Why does LongSummaryStatistics implements IntConsumer?












7














Why does LongSummaryStatistics implements IntConsumer when there is IntSummaryStatistics which also implements IntConsumer?










share|improve this question





























    7














    Why does LongSummaryStatistics implements IntConsumer when there is IntSummaryStatistics which also implements IntConsumer?










    share|improve this question



























      7












      7








      7


      3





      Why does LongSummaryStatistics implements IntConsumer when there is IntSummaryStatistics which also implements IntConsumer?










      share|improve this question















      Why does LongSummaryStatistics implements IntConsumer when there is IntSummaryStatistics which also implements IntConsumer?







      java java-8 java-stream






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      Stefan Zobel

      2,44031828




      2,44031828










      asked 2 hours ago









      mkjh

      375112




      375112
























          1 Answer
          1






          active

          oldest

          votes


















          9














          LongSummaryStatistics implements IntConsumer in order that it can accept int values as well as long values.



          For example, this allows you to pass it to a method requiring an IntConsumer in order to consume some int data abstractly:



          LongSummaryStatistics lss = new LongSummaryStatistics();
          someMethod(lss);

          void someMethod(IntConsumer consumer) { ... }


          There's no real reason why a LongSummaryStatistics shouldn't be usable for this purpose: int can always be widened to long without loss. However, the type system wouldn't allow lss to be used as a parameter to someMethod unless LongSummaryStatistics implemented IntConsumer directly.



          True, you could do this without implementing the interface, using a lambda:



          someMethod(i -> lss.consume(i));


          but it's just a bit neater to use the reference directly.






          share|improve this answer



















          • 1




            A follow-up question that comes to my mind, why not separate them out, why let consumers define separate streams of int and long and then mix them?
            – nullpointer
            1 hour ago






          • 1




            @nullpointer try defining a class which doesn't implement IntConsumer, and then pass it to a method which requires an IntConsumer parameter.
            – Andy Turner
            1 hour ago






          • 1




            I don't understand what you mean by "why let consumers define separate streams of int and long and then mix them"? Streams are not the only sources of data for *SummaryStatistics, you can invoke the methods directly.
            – Andy Turner
            1 hour ago












          • True, and when invoking the *SummaryStatistics directly too, why should one be collecting stats for varied type(int at once and long at another) of data is what I am thinking about. Maybe thinking too much there, but seemingly an example would cool down my thought process I guess.
            – nullpointer
            1 hour ago











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003796%2fwhy-does-longsummarystatistics-implements-intconsumer%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          9














          LongSummaryStatistics implements IntConsumer in order that it can accept int values as well as long values.



          For example, this allows you to pass it to a method requiring an IntConsumer in order to consume some int data abstractly:



          LongSummaryStatistics lss = new LongSummaryStatistics();
          someMethod(lss);

          void someMethod(IntConsumer consumer) { ... }


          There's no real reason why a LongSummaryStatistics shouldn't be usable for this purpose: int can always be widened to long without loss. However, the type system wouldn't allow lss to be used as a parameter to someMethod unless LongSummaryStatistics implemented IntConsumer directly.



          True, you could do this without implementing the interface, using a lambda:



          someMethod(i -> lss.consume(i));


          but it's just a bit neater to use the reference directly.






          share|improve this answer



















          • 1




            A follow-up question that comes to my mind, why not separate them out, why let consumers define separate streams of int and long and then mix them?
            – nullpointer
            1 hour ago






          • 1




            @nullpointer try defining a class which doesn't implement IntConsumer, and then pass it to a method which requires an IntConsumer parameter.
            – Andy Turner
            1 hour ago






          • 1




            I don't understand what you mean by "why let consumers define separate streams of int and long and then mix them"? Streams are not the only sources of data for *SummaryStatistics, you can invoke the methods directly.
            – Andy Turner
            1 hour ago












          • True, and when invoking the *SummaryStatistics directly too, why should one be collecting stats for varied type(int at once and long at another) of data is what I am thinking about. Maybe thinking too much there, but seemingly an example would cool down my thought process I guess.
            – nullpointer
            1 hour ago
















          9














          LongSummaryStatistics implements IntConsumer in order that it can accept int values as well as long values.



          For example, this allows you to pass it to a method requiring an IntConsumer in order to consume some int data abstractly:



          LongSummaryStatistics lss = new LongSummaryStatistics();
          someMethod(lss);

          void someMethod(IntConsumer consumer) { ... }


          There's no real reason why a LongSummaryStatistics shouldn't be usable for this purpose: int can always be widened to long without loss. However, the type system wouldn't allow lss to be used as a parameter to someMethod unless LongSummaryStatistics implemented IntConsumer directly.



          True, you could do this without implementing the interface, using a lambda:



          someMethod(i -> lss.consume(i));


          but it's just a bit neater to use the reference directly.






          share|improve this answer



















          • 1




            A follow-up question that comes to my mind, why not separate them out, why let consumers define separate streams of int and long and then mix them?
            – nullpointer
            1 hour ago






          • 1




            @nullpointer try defining a class which doesn't implement IntConsumer, and then pass it to a method which requires an IntConsumer parameter.
            – Andy Turner
            1 hour ago






          • 1




            I don't understand what you mean by "why let consumers define separate streams of int and long and then mix them"? Streams are not the only sources of data for *SummaryStatistics, you can invoke the methods directly.
            – Andy Turner
            1 hour ago












          • True, and when invoking the *SummaryStatistics directly too, why should one be collecting stats for varied type(int at once and long at another) of data is what I am thinking about. Maybe thinking too much there, but seemingly an example would cool down my thought process I guess.
            – nullpointer
            1 hour ago














          9












          9








          9






          LongSummaryStatistics implements IntConsumer in order that it can accept int values as well as long values.



          For example, this allows you to pass it to a method requiring an IntConsumer in order to consume some int data abstractly:



          LongSummaryStatistics lss = new LongSummaryStatistics();
          someMethod(lss);

          void someMethod(IntConsumer consumer) { ... }


          There's no real reason why a LongSummaryStatistics shouldn't be usable for this purpose: int can always be widened to long without loss. However, the type system wouldn't allow lss to be used as a parameter to someMethod unless LongSummaryStatistics implemented IntConsumer directly.



          True, you could do this without implementing the interface, using a lambda:



          someMethod(i -> lss.consume(i));


          but it's just a bit neater to use the reference directly.






          share|improve this answer














          LongSummaryStatistics implements IntConsumer in order that it can accept int values as well as long values.



          For example, this allows you to pass it to a method requiring an IntConsumer in order to consume some int data abstractly:



          LongSummaryStatistics lss = new LongSummaryStatistics();
          someMethod(lss);

          void someMethod(IntConsumer consumer) { ... }


          There's no real reason why a LongSummaryStatistics shouldn't be usable for this purpose: int can always be widened to long without loss. However, the type system wouldn't allow lss to be used as a parameter to someMethod unless LongSummaryStatistics implemented IntConsumer directly.



          True, you could do this without implementing the interface, using a lambda:



          someMethod(i -> lss.consume(i));


          but it's just a bit neater to use the reference directly.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago

























          answered 2 hours ago









          Andy Turner

          80.3k879133




          80.3k879133








          • 1




            A follow-up question that comes to my mind, why not separate them out, why let consumers define separate streams of int and long and then mix them?
            – nullpointer
            1 hour ago






          • 1




            @nullpointer try defining a class which doesn't implement IntConsumer, and then pass it to a method which requires an IntConsumer parameter.
            – Andy Turner
            1 hour ago






          • 1




            I don't understand what you mean by "why let consumers define separate streams of int and long and then mix them"? Streams are not the only sources of data for *SummaryStatistics, you can invoke the methods directly.
            – Andy Turner
            1 hour ago












          • True, and when invoking the *SummaryStatistics directly too, why should one be collecting stats for varied type(int at once and long at another) of data is what I am thinking about. Maybe thinking too much there, but seemingly an example would cool down my thought process I guess.
            – nullpointer
            1 hour ago














          • 1




            A follow-up question that comes to my mind, why not separate them out, why let consumers define separate streams of int and long and then mix them?
            – nullpointer
            1 hour ago






          • 1




            @nullpointer try defining a class which doesn't implement IntConsumer, and then pass it to a method which requires an IntConsumer parameter.
            – Andy Turner
            1 hour ago






          • 1




            I don't understand what you mean by "why let consumers define separate streams of int and long and then mix them"? Streams are not the only sources of data for *SummaryStatistics, you can invoke the methods directly.
            – Andy Turner
            1 hour ago












          • True, and when invoking the *SummaryStatistics directly too, why should one be collecting stats for varied type(int at once and long at another) of data is what I am thinking about. Maybe thinking too much there, but seemingly an example would cool down my thought process I guess.
            – nullpointer
            1 hour ago








          1




          1




          A follow-up question that comes to my mind, why not separate them out, why let consumers define separate streams of int and long and then mix them?
          – nullpointer
          1 hour ago




          A follow-up question that comes to my mind, why not separate them out, why let consumers define separate streams of int and long and then mix them?
          – nullpointer
          1 hour ago




          1




          1




          @nullpointer try defining a class which doesn't implement IntConsumer, and then pass it to a method which requires an IntConsumer parameter.
          – Andy Turner
          1 hour ago




          @nullpointer try defining a class which doesn't implement IntConsumer, and then pass it to a method which requires an IntConsumer parameter.
          – Andy Turner
          1 hour ago




          1




          1




          I don't understand what you mean by "why let consumers define separate streams of int and long and then mix them"? Streams are not the only sources of data for *SummaryStatistics, you can invoke the methods directly.
          – Andy Turner
          1 hour ago






          I don't understand what you mean by "why let consumers define separate streams of int and long and then mix them"? Streams are not the only sources of data for *SummaryStatistics, you can invoke the methods directly.
          – Andy Turner
          1 hour ago














          True, and when invoking the *SummaryStatistics directly too, why should one be collecting stats for varied type(int at once and long at another) of data is what I am thinking about. Maybe thinking too much there, but seemingly an example would cool down my thought process I guess.
          – nullpointer
          1 hour ago




          True, and when invoking the *SummaryStatistics directly too, why should one be collecting stats for varied type(int at once and long at another) of data is what I am thinking about. Maybe thinking too much there, but seemingly an example would cool down my thought process I guess.
          – nullpointer
          1 hour ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003796%2fwhy-does-longsummarystatistics-implements-intconsumer%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Eastern Orthodox Church

          Zagreb

          Understanding the information contained in the Deep Space Network XML data?