参考博客:https://www.cnblogs.com/singlecodeworld/p/9887926.html
//使用枚举类型,能够限定取值的范围
//使程序在编译时就会及早的返现错误
//这样程序会更加健壮
public class EnumTest03 {
public static void main(String[] args) throws Exception{
Result r = method1(10, 2);
if (r == Result.SUCCESS) {
System.out.println("成功!");
}
if (r == Result.FAILURE) {
System.out.println("失败!");
}
}
//正确返回 SUCCESS,失败返回:FAILURE
private static Result method1(int value1, int value2) {
try {
int v = value1/value2;
return Result.SUCCESS;
}catch(Exception e) {
return Result.FAILURE;
}
}
}
enum Result {
SUCCESS,FAILURE
}