SonarQube Violation Java 8 Bifunction Requirement











up vote
2
down vote

favorite












I defined a functional interface with one method declaration, and the implementation of the method in a class of another project. SonarQube violation is that I am redefining a standard functional interface that is already provided in Java 8.



@FunctionalInterface
/*access modifier*/ interface XYZService {
XYZProfile makeRESTServiceGetCall(String str, Integer id);
}

"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"


The REST service GET call simply takes the inputs and returns XYZProfile. Generally, the project structure requires the using interfaces, but to solve the Sonar violations shall I remove the 'interface', and change the makeRESTServiceGetCall method call to the bifunction syntax?










share|improve this question




















  • 3




    You didn’t ask a question. You just appended a question mark to a statement.
    – Holger
    Nov 20 at 14:02















up vote
2
down vote

favorite












I defined a functional interface with one method declaration, and the implementation of the method in a class of another project. SonarQube violation is that I am redefining a standard functional interface that is already provided in Java 8.



@FunctionalInterface
/*access modifier*/ interface XYZService {
XYZProfile makeRESTServiceGetCall(String str, Integer id);
}

"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"


The REST service GET call simply takes the inputs and returns XYZProfile. Generally, the project structure requires the using interfaces, but to solve the Sonar violations shall I remove the 'interface', and change the makeRESTServiceGetCall method call to the bifunction syntax?










share|improve this question




















  • 3




    You didn’t ask a question. You just appended a question mark to a statement.
    – Holger
    Nov 20 at 14:02













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I defined a functional interface with one method declaration, and the implementation of the method in a class of another project. SonarQube violation is that I am redefining a standard functional interface that is already provided in Java 8.



@FunctionalInterface
/*access modifier*/ interface XYZService {
XYZProfile makeRESTServiceGetCall(String str, Integer id);
}

"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"


The REST service GET call simply takes the inputs and returns XYZProfile. Generally, the project structure requires the using interfaces, but to solve the Sonar violations shall I remove the 'interface', and change the makeRESTServiceGetCall method call to the bifunction syntax?










share|improve this question















I defined a functional interface with one method declaration, and the implementation of the method in a class of another project. SonarQube violation is that I am redefining a standard functional interface that is already provided in Java 8.



@FunctionalInterface
/*access modifier*/ interface XYZService {
XYZProfile makeRESTServiceGetCall(String str, Integer id);
}

"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"Drop this interface in favor of "java.util.function.BiFunction<String,Integer,XYZProfile>"


The REST service GET call simply takes the inputs and returns XYZProfile. Generally, the project structure requires the using interfaces, but to solve the Sonar violations shall I remove the 'interface', and change the makeRESTServiceGetCall method call to the bifunction syntax?







java spring-boot java-8 sonarqube functional-interface






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 14:47









nullpointer

38.9k1074148




38.9k1074148










asked Nov 20 at 13:57









Parth Patel

133




133








  • 3




    You didn’t ask a question. You just appended a question mark to a statement.
    – Holger
    Nov 20 at 14:02














  • 3




    You didn’t ask a question. You just appended a question mark to a statement.
    – Holger
    Nov 20 at 14:02








3




3




You didn’t ask a question. You just appended a question mark to a statement.
– Holger
Nov 20 at 14:02




You didn’t ask a question. You just appended a question mark to a statement.
– Holger
Nov 20 at 14:02












1 Answer
1






active

oldest

votes

















up vote
1
down vote













The violation suggests that there is already a Functional Interface that can solve the purpose of what you're trying to implement using your custom interface i.e. BiFunction<T,U,R>.



So at places where you're defining the method makeRESTServiceGetCall of your XYZService, you can instead simply create a BiFunction in your code as:



BiFunction<String, Integer, XYZProfile> xyzProfileBiFunction = (string, integer) -> {
return xyzProfile; // the GET call implementation using 'string' &'integer'
};


and then at places where you were calling the method makeRESTServiceGetCall, you can simply apply the above implementation as :



XYZProfile xyzProfileNullPointer = xyzProfileBiFunction.apply("nullpointer", 0);
XYZProfile xyzProfileParth = xyzProfileBiFunction.apply("Parth", 1);





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%2f53394623%2fsonarqube-violation-java-8-bifunction-requirement%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








    up vote
    1
    down vote













    The violation suggests that there is already a Functional Interface that can solve the purpose of what you're trying to implement using your custom interface i.e. BiFunction<T,U,R>.



    So at places where you're defining the method makeRESTServiceGetCall of your XYZService, you can instead simply create a BiFunction in your code as:



    BiFunction<String, Integer, XYZProfile> xyzProfileBiFunction = (string, integer) -> {
    return xyzProfile; // the GET call implementation using 'string' &'integer'
    };


    and then at places where you were calling the method makeRESTServiceGetCall, you can simply apply the above implementation as :



    XYZProfile xyzProfileNullPointer = xyzProfileBiFunction.apply("nullpointer", 0);
    XYZProfile xyzProfileParth = xyzProfileBiFunction.apply("Parth", 1);





    share|improve this answer

























      up vote
      1
      down vote













      The violation suggests that there is already a Functional Interface that can solve the purpose of what you're trying to implement using your custom interface i.e. BiFunction<T,U,R>.



      So at places where you're defining the method makeRESTServiceGetCall of your XYZService, you can instead simply create a BiFunction in your code as:



      BiFunction<String, Integer, XYZProfile> xyzProfileBiFunction = (string, integer) -> {
      return xyzProfile; // the GET call implementation using 'string' &'integer'
      };


      and then at places where you were calling the method makeRESTServiceGetCall, you can simply apply the above implementation as :



      XYZProfile xyzProfileNullPointer = xyzProfileBiFunction.apply("nullpointer", 0);
      XYZProfile xyzProfileParth = xyzProfileBiFunction.apply("Parth", 1);





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        The violation suggests that there is already a Functional Interface that can solve the purpose of what you're trying to implement using your custom interface i.e. BiFunction<T,U,R>.



        So at places where you're defining the method makeRESTServiceGetCall of your XYZService, you can instead simply create a BiFunction in your code as:



        BiFunction<String, Integer, XYZProfile> xyzProfileBiFunction = (string, integer) -> {
        return xyzProfile; // the GET call implementation using 'string' &'integer'
        };


        and then at places where you were calling the method makeRESTServiceGetCall, you can simply apply the above implementation as :



        XYZProfile xyzProfileNullPointer = xyzProfileBiFunction.apply("nullpointer", 0);
        XYZProfile xyzProfileParth = xyzProfileBiFunction.apply("Parth", 1);





        share|improve this answer












        The violation suggests that there is already a Functional Interface that can solve the purpose of what you're trying to implement using your custom interface i.e. BiFunction<T,U,R>.



        So at places where you're defining the method makeRESTServiceGetCall of your XYZService, you can instead simply create a BiFunction in your code as:



        BiFunction<String, Integer, XYZProfile> xyzProfileBiFunction = (string, integer) -> {
        return xyzProfile; // the GET call implementation using 'string' &'integer'
        };


        and then at places where you were calling the method makeRESTServiceGetCall, you can simply apply the above implementation as :



        XYZProfile xyzProfileNullPointer = xyzProfileBiFunction.apply("nullpointer", 0);
        XYZProfile xyzProfileParth = xyzProfileBiFunction.apply("Parth", 1);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 at 14:37









        nullpointer

        38.9k1074148




        38.9k1074148






























            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%2f53394623%2fsonarqube-violation-java-8-bifunction-requirement%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

            Wiesbaden

            Marschland

            Dieringhausen