Java 中是否有 EXIT_SUCCESS 和 EXIT_FAILURE 的替代品?

2022-01-19 00:00:00 return exit java

在 C 程序中,我一般在 exit() 函数中使用 EXIT_SUCCESSEXIT_FAILURE 来提高程序的清晰度和可理解性.

In a C program, I generally use EXIT_SUCCESS or EXIT_FAILURE in exit() function to improve clarity and understandability of the program.

但在 System.exit() 中我无法使用这些 MACROS.

But in System.exit() I couldn't use these MACROS.

我可以将自己的界面定义为

I can define my own interface as

public interface ReturnValues {
  public int EXIT_SUCCESS = 0;
  public int EXIT_FAILURE = 1;
}

除了我自己的实现,java中还有其他方法可以使用这些宏吗?(例如使用预定义的库类变量或通过实现预定义的接口等)

Other than my own implementation, is there any other way in java to use these Macros? (like using predefined library class variables or by implementing predefined interface etc..)

推荐答案

不,Java 中没有用于 SUCCESS 和 FAILURE 的预定义常量.当然,因为可能存在几种不同类型的故障,具体取决于每个特定的应用程序.

No, there is no predefined constants in Java for SUCCESS and FAILURE. Certainly because there might be several different kinds of failures, depending on each specific application.

相关文章