Passing int[][] as generic parameter











up vote
10
down vote

favorite
2












public static <T> void func1(T arr) {
...
}




public static <T> void func2(T arr) {
...
}


I'm trying to pass a 2-dimensional array, int arr.



I cannot use func1(arr) , but I can use func2(arr)



Can someone explain me how this works?










share|improve this question




























    up vote
    10
    down vote

    favorite
    2












    public static <T> void func1(T arr) {
    ...
    }




    public static <T> void func2(T arr) {
    ...
    }


    I'm trying to pass a 2-dimensional array, int arr.



    I cannot use func1(arr) , but I can use func2(arr)



    Can someone explain me how this works?










    share|improve this question


























      up vote
      10
      down vote

      favorite
      2









      up vote
      10
      down vote

      favorite
      2






      2





      public static <T> void func1(T arr) {
      ...
      }




      public static <T> void func2(T arr) {
      ...
      }


      I'm trying to pass a 2-dimensional array, int arr.



      I cannot use func1(arr) , but I can use func2(arr)



      Can someone explain me how this works?










      share|improve this question















      public static <T> void func1(T arr) {
      ...
      }




      public static <T> void func2(T arr) {
      ...
      }


      I'm trying to pass a 2-dimensional array, int arr.



      I cannot use func1(arr) , but I can use func2(arr)



      Can someone explain me how this works?







      java generics methods parameters parameter-passing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      Muntasir

      6021818




      6021818










      asked 2 days ago









      Sumit Das

      524615




      524615
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          20
          down vote













          T represents an array of some generic object. Any array type (including int) is an object. Therefore, int is a valid T when T = int.



          However, because int is not an object, int is not a valid T.






          share|improve this answer

















          • 4




            To expand on this, you could change it to Integer arr; and it should work.
            – LadyCailin
            2 days ago






          • 3




            @LadyCailin true, but in most cases when you need multi-dimensional arrays, it is really bad idea to use wrapper types
            – user1643723
            2 days ago


















          up vote
          1
          down vote













          If you you use Integer instead of int, you should be able to:




          • call func1 with Integer arr

          • call func2 with Integer arr or Integer arr






          share|improve this answer























            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',
            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%2f53355630%2fpassing-int-as-generic-parameter%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            20
            down vote













            T represents an array of some generic object. Any array type (including int) is an object. Therefore, int is a valid T when T = int.



            However, because int is not an object, int is not a valid T.






            share|improve this answer

















            • 4




              To expand on this, you could change it to Integer arr; and it should work.
              – LadyCailin
              2 days ago






            • 3




              @LadyCailin true, but in most cases when you need multi-dimensional arrays, it is really bad idea to use wrapper types
              – user1643723
              2 days ago















            up vote
            20
            down vote













            T represents an array of some generic object. Any array type (including int) is an object. Therefore, int is a valid T when T = int.



            However, because int is not an object, int is not a valid T.






            share|improve this answer

















            • 4




              To expand on this, you could change it to Integer arr; and it should work.
              – LadyCailin
              2 days ago






            • 3




              @LadyCailin true, but in most cases when you need multi-dimensional arrays, it is really bad idea to use wrapper types
              – user1643723
              2 days ago













            up vote
            20
            down vote










            up vote
            20
            down vote









            T represents an array of some generic object. Any array type (including int) is an object. Therefore, int is a valid T when T = int.



            However, because int is not an object, int is not a valid T.






            share|improve this answer












            T represents an array of some generic object. Any array type (including int) is an object. Therefore, int is a valid T when T = int.



            However, because int is not an object, int is not a valid T.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 days ago









            Joe C

            9,81352341




            9,81352341








            • 4




              To expand on this, you could change it to Integer arr; and it should work.
              – LadyCailin
              2 days ago






            • 3




              @LadyCailin true, but in most cases when you need multi-dimensional arrays, it is really bad idea to use wrapper types
              – user1643723
              2 days ago














            • 4




              To expand on this, you could change it to Integer arr; and it should work.
              – LadyCailin
              2 days ago






            • 3




              @LadyCailin true, but in most cases when you need multi-dimensional arrays, it is really bad idea to use wrapper types
              – user1643723
              2 days ago








            4




            4




            To expand on this, you could change it to Integer arr; and it should work.
            – LadyCailin
            2 days ago




            To expand on this, you could change it to Integer arr; and it should work.
            – LadyCailin
            2 days ago




            3




            3




            @LadyCailin true, but in most cases when you need multi-dimensional arrays, it is really bad idea to use wrapper types
            – user1643723
            2 days ago




            @LadyCailin true, but in most cases when you need multi-dimensional arrays, it is really bad idea to use wrapper types
            – user1643723
            2 days ago












            up vote
            1
            down vote













            If you you use Integer instead of int, you should be able to:




            • call func1 with Integer arr

            • call func2 with Integer arr or Integer arr






            share|improve this answer



























              up vote
              1
              down vote













              If you you use Integer instead of int, you should be able to:




              • call func1 with Integer arr

              • call func2 with Integer arr or Integer arr






              share|improve this answer

























                up vote
                1
                down vote










                up vote
                1
                down vote









                If you you use Integer instead of int, you should be able to:




                • call func1 with Integer arr

                • call func2 with Integer arr or Integer arr






                share|improve this answer














                If you you use Integer instead of int, you should be able to:




                • call func1 with Integer arr

                • call func2 with Integer arr or Integer arr







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 days ago

























                answered 2 days ago









                TeeKea

                833617




                833617






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355630%2fpassing-int-as-generic-parameter%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

                    Le Mesnil-Réaume

                    Bundesstraße 106

                    Ida-Boy-Ed-Garten