相关文章推荐
开朗的丝瓜  ·  AttributeError: ...·  11 月前    · 
慈祥的皮带  ·  在 Azure ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a method in which there is a if else conditions . The if-else looks something similar as below.

public void agreementCoduct(String agreement) {
       if(agreement.equals("Pass")) {
         { //do someting
           return; // getting Remove this Redundant Jump
         } else if(aggrement.equals("NotPass")) {
           // do something
           return; // getting Remove this Redundant Jump
        } else {
          // do something 
          return; // getting Remove this Redundant Jump

I'm running Sonarqube to check the code quality. It is showing the message "Remove this redundant jump." . I want to know how can I remove this Code smell and still achieve what I want. as this is void method so return; should work fine?

you're using if if-else else so you can remove them safely, as once you're in a block you will not enter another one – Lino Apr 10, 2019 at 8:47

The return statements have no effect because you do not have any code after the if-elseif-else block. If you remove the return statements, your code will leave the matching if-block and return at the end of the method.

Only the first one of the if-elseif-else blocks that evaluates to true gets executed.

A void-method has an implicit "return" statement in the end.

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.