Answer the question
In order to leave comments, you need to log in
JSF Java EE Is multiple return required in MB methods?
Quite often I came across constructions of this kind in the methods of @ManagedBean classes:
if(condition) {
method1();
return null;
} else if (condition2) {
method2();
return null;
} else {
method3();
return null;
}
Actually a question: whether there is any sense (except, probably, the best code readability) in these multiple returns of identical values (in an example - null). Wouldn't it be better to just return null once at the end, after the whole construction? The same constructs are used in the documentation from oracle (see 12.3.1.) https://docs.oracle.com/javaee/7/tutorial/jsf-deve...
Answer the question
In order to leave comments, you need to log in
The code should be as simple as possible, the behavior should be as explicit as possible. This approach allows you to save "thought fuel" when writing or reading code, it is easier to keep it in your head.
In the above example, a bunch of returns can be replaced with one because condition branching does not lead to multiple results. Perhaps left to replace null with the result of the function executed in the condition (which would be correct).
However, there are issues with the code, as nApoBo3 already noted .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question