Return means that, yes, but it also means "Give this value to the part of the code that is calling this function". In anonymous functions, this is a State, and when writing your code, you need to make sure that every single scenario in the code is covered by the return values:
- Code: Select all • Expand view
if (whatever) {
return resolveState("Blah");
}
else {
return resolveState("Blah2");
}
This will compile, since there are only 2 scenarios - whatever is true, and whatever is false. Both of these have a corresponding return value, and the compiler is smart enough to know that there is no possible other path.
- Code: Select all • Expand view
if (whatever) {
return resolveState("Blah");
}
else if (whatever2) {
return resolveState("Blah2");
}
This
won't compile, as there are 3 scenarios - "whatever is true", "whatever is false and whatever2 is true", and "whatever is false, and whatever2 is false". In the code, the 3rd scenario is beyond the
else if (whatever2) {} block - therefore, it needs a
return resolveState(null) to finish off the chain, otherwise it's (implicitly) returning
void in a function that needs to return
State - void is not a State, so that doesn't work.