优化后的代码如下:

final List roles = new ArrayList<>(); final Boolean existAppraise = activityAppraiseeService.existByEmpCode(empCode); if (BooleanUtils.isTrue(existAppraise)) { roles.add(UserTypeEnum.APPRAISEE.getValue()); }

final Boolean existExaminer = activityExaminerService.existByEmpCode(empCode); if (BooleanUtils.isTrue(existExaminer)) { roles.add(UserTypeEnum.EXAMINER.getValue()); }

return roles;

Java 代码优化:使用 ArrayList 和 BooleanUtils.isTrue() 方法

原文地址: https://www.cveoy.top/t/topic/o4hC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录