返回false 还是抛出异常?
目前看来是抛出异常的方式在多条件的情况更好。不知道大家怎么看
public class A {public boolean get() {if(!method1()){return false;} if(!method2()){ return false;} if(!method3()){ return false;}return true;}public boolean get2() {try {method1();method2();method3();} catch (Exception e) { return false;}return true;}public boolean method1(){return true;}public boolean method2(){return true;}public boolean method3(){return true;}} 1 楼 devilyard 21 小时前 赞同,false有时候会被遗忘,但异常就一定会被捕获 2 楼 xiaokek 20 小时前 本人认为捕获异常更灵活,它不要求方法的返回值必须为boolean,而且异常也可以多种多样,不像boolean只有真和假。 3 楼 jinnianshilongnian 19 小时前 我认为这个要根据实际情况