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?
–
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.