Is there any way to force the compiler (annotation or othewise) to realize a java function is never returning (i.e. always throwing), so that subsequently it will not error out its usages as the last statement in other functions returning non void?
Here’s a simplified/made-up example:
int add( int x, int y ) {
throwNotImplemented(); // compiler error here: no return value.
}
// How can I annotate (or change) this function, so compiling add will not yield
// an error since this function always throws?
void throwNotImplemented() {
... some stuff here (generally logging, sometimes recovery, etc)
throw new NotImplementedException();
}
Thank you.
No, it’s not possible.
Note, however, that you can easily work it around as follows: