Is there a “noreturn” keyword in Java

Sometimes I want to write an error () function, which will eventually call system Exit(), which means that this function will never return However, if I call error () in other functions, I would like to write as follows:

int fun() {
...
  error();
}

But the compiler insists on returning an int value after the error () call, because it doesn't know that error () will never return I will certainly return an arbitrary int, but if the return type is a complex class, I need to construct it in the code, which is a waste of time Is there any way to tell the compiler that a function will never return?

resolvent

Solution

You should throw a runtimeException@ H_ 403_ 4@ @H_ 403_ 4@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>