How to find module of Integer(Generic) in Java











up vote
0
down vote

favorite












I have Dual LinkedList (DLL) that I wanna separate in two DLLs, one with only odd numbers and the other with even. But I'm getting error when I try to ((Generic)%2==0)



Error Message: The method parseInt(E) is undefined for the type DLL<E>



public DLL parni() {
DLL<E>niza = new DLL<E>();
DLLNode<E>tmp = first;

while(tmp.succ != null) {
if((parseInt(tmp.element)) % 2 != 0) {
niza.insertLast(tmp.element);
delete(tmp);
}
tmp = tmp.succ;
}
}


tmp.element is generic of type E



By the way, I tried adding the super class Number in the DLL class



class DLL<E extends Number>


Any advices?










share|improve this question
























  • You should use tmp.element.intValue() instead.
    – victini
    Nov 19 at 12:01










  • What's wrong with it? It compiles (I added first and a return value to the method)
    – Michael
    Nov 19 at 12:02












  • @victini thanks man it worked
    – borceste
    Nov 19 at 13:55















up vote
0
down vote

favorite












I have Dual LinkedList (DLL) that I wanna separate in two DLLs, one with only odd numbers and the other with even. But I'm getting error when I try to ((Generic)%2==0)



Error Message: The method parseInt(E) is undefined for the type DLL<E>



public DLL parni() {
DLL<E>niza = new DLL<E>();
DLLNode<E>tmp = first;

while(tmp.succ != null) {
if((parseInt(tmp.element)) % 2 != 0) {
niza.insertLast(tmp.element);
delete(tmp);
}
tmp = tmp.succ;
}
}


tmp.element is generic of type E



By the way, I tried adding the super class Number in the DLL class



class DLL<E extends Number>


Any advices?










share|improve this question
























  • You should use tmp.element.intValue() instead.
    – victini
    Nov 19 at 12:01










  • What's wrong with it? It compiles (I added first and a return value to the method)
    – Michael
    Nov 19 at 12:02












  • @victini thanks man it worked
    – borceste
    Nov 19 at 13:55













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have Dual LinkedList (DLL) that I wanna separate in two DLLs, one with only odd numbers and the other with even. But I'm getting error when I try to ((Generic)%2==0)



Error Message: The method parseInt(E) is undefined for the type DLL<E>



public DLL parni() {
DLL<E>niza = new DLL<E>();
DLLNode<E>tmp = first;

while(tmp.succ != null) {
if((parseInt(tmp.element)) % 2 != 0) {
niza.insertLast(tmp.element);
delete(tmp);
}
tmp = tmp.succ;
}
}


tmp.element is generic of type E



By the way, I tried adding the super class Number in the DLL class



class DLL<E extends Number>


Any advices?










share|improve this question















I have Dual LinkedList (DLL) that I wanna separate in two DLLs, one with only odd numbers and the other with even. But I'm getting error when I try to ((Generic)%2==0)



Error Message: The method parseInt(E) is undefined for the type DLL<E>



public DLL parni() {
DLL<E>niza = new DLL<E>();
DLLNode<E>tmp = first;

while(tmp.succ != null) {
if((parseInt(tmp.element)) % 2 != 0) {
niza.insertLast(tmp.element);
delete(tmp);
}
tmp = tmp.succ;
}
}


tmp.element is generic of type E



By the way, I tried adding the super class Number in the DLL class



class DLL<E extends Number>


Any advices?







java generics linked-list






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 12:08









deHaar

2,13831326




2,13831326










asked Nov 19 at 11:56









borceste

82




82












  • You should use tmp.element.intValue() instead.
    – victini
    Nov 19 at 12:01










  • What's wrong with it? It compiles (I added first and a return value to the method)
    – Michael
    Nov 19 at 12:02












  • @victini thanks man it worked
    – borceste
    Nov 19 at 13:55


















  • You should use tmp.element.intValue() instead.
    – victini
    Nov 19 at 12:01










  • What's wrong with it? It compiles (I added first and a return value to the method)
    – Michael
    Nov 19 at 12:02












  • @victini thanks man it worked
    – borceste
    Nov 19 at 13:55
















You should use tmp.element.intValue() instead.
– victini
Nov 19 at 12:01




You should use tmp.element.intValue() instead.
– victini
Nov 19 at 12:01












What's wrong with it? It compiles (I added first and a return value to the method)
– Michael
Nov 19 at 12:02






What's wrong with it? It compiles (I added first and a return value to the method)
– Michael
Nov 19 at 12:02














@victini thanks man it worked
– borceste
Nov 19 at 13:55




@victini thanks man it worked
– borceste
Nov 19 at 13:55












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










If E extends java.lang.Number, you can try like this:



if(tmp.element.intValue() % 2 != 0)





share|improve this answer




























    up vote
    1
    down vote













    Simple: you wrote your own class DLL<E extends Number>.



    Now you wrote code that intends to call a method parseInt() belonging to your own class DLL.



    The compiler is telling you:




    The method parseInt(E) is undefined for the type DLL




    that you didn't write that method yet.



    In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.



    Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.






    share|improve this answer





















    • For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
      – Michael
      Nov 19 at 12:05













    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%2f53374134%2fhow-to-find-module-of-integergeneric-in-java%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
    0
    down vote



    accepted










    If E extends java.lang.Number, you can try like this:



    if(tmp.element.intValue() % 2 != 0)





    share|improve this answer

























      up vote
      0
      down vote



      accepted










      If E extends java.lang.Number, you can try like this:



      if(tmp.element.intValue() % 2 != 0)





      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        If E extends java.lang.Number, you can try like this:



        if(tmp.element.intValue() % 2 != 0)





        share|improve this answer












        If E extends java.lang.Number, you can try like this:



        if(tmp.element.intValue() % 2 != 0)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 12:08









        victini

        1146




        1146
























            up vote
            1
            down vote













            Simple: you wrote your own class DLL<E extends Number>.



            Now you wrote code that intends to call a method parseInt() belonging to your own class DLL.



            The compiler is telling you:




            The method parseInt(E) is undefined for the type DLL




            that you didn't write that method yet.



            In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.



            Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.






            share|improve this answer





















            • For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
              – Michael
              Nov 19 at 12:05

















            up vote
            1
            down vote













            Simple: you wrote your own class DLL<E extends Number>.



            Now you wrote code that intends to call a method parseInt() belonging to your own class DLL.



            The compiler is telling you:




            The method parseInt(E) is undefined for the type DLL




            that you didn't write that method yet.



            In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.



            Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.






            share|improve this answer





















            • For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
              – Michael
              Nov 19 at 12:05















            up vote
            1
            down vote










            up vote
            1
            down vote









            Simple: you wrote your own class DLL<E extends Number>.



            Now you wrote code that intends to call a method parseInt() belonging to your own class DLL.



            The compiler is telling you:




            The method parseInt(E) is undefined for the type DLL




            that you didn't write that method yet.



            In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.



            Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.






            share|improve this answer












            Simple: you wrote your own class DLL<E extends Number>.



            Now you wrote code that intends to call a method parseInt() belonging to your own class DLL.



            The compiler is telling you:




            The method parseInt(E) is undefined for the type DLL




            that you didn't write that method yet.



            In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.



            Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 19 at 11:59









            GhostCat

            86.5k1684143




            86.5k1684143












            • For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
              – Michael
              Nov 19 at 12:05




















            • For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
              – Michael
              Nov 19 at 12:05


















            For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
            – Michael
            Nov 19 at 12:05






            For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
            – Michael
            Nov 19 at 12:05




















            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%2f53374134%2fhow-to-find-module-of-integergeneric-in-java%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

            Costa Masnaga

            Fotorealismo

            Sidney Franklin