내가 선택적 개체를 사용하여 아래의 코드 (나는 jpaConnector을 제어하지 않음) 다시 할 : 나는 지금까지이 achievied 한재 작성 서비스 요청을 사용하여 선택적 항목
public boolean deleteLockStatus() {
IMdss service = jpaConnector.getMdssService();
if (service == null) {
return false;
}
ServiceResponse response = null;
try {
response = service.deleteLockStatus();
} catch (Exception e) {
e.printStackTrace();
}
if (response == null) {
return false;
}
if (response.isError()) {
return false;
}
return true;
}
:
public boolean deleteLockStatus() {
Optional<IMdss> service = Optional.ofNullable(jpaConnector.getMdssService());
if (!service.isPresent()) { return false; }
Optional<ServiceResponse> response = Optional.empty();
try {
response = Optional.ofNullable(service.get().deleteLockStatus());
if (response.isPresent() == false || response.get().isError()) {
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
이 더 나은가요 및 더 많은 네이티브 자바 8 방법? 고맙습니다!!!
감사합니다. 1 분 O.O ... 나는 stackTrace를 인쇄 할 필요가 없지만 예외를 처리해야합니다 ...하지만 나는 한 줄만 저장합니다.? – Shakka
@Shakka'flatMap' 람다의 내용을 자신의 함수로 옮긴 다음 메소드 참조로 바꾸는 것을 고려해 볼 수 있습니다.하지만 좀 더 가독성이 있는지를 결정하는 것은 당신에게 달려 있습니다. – Michael
작은 오류가 수정되었습니다. 마지막 괄호는 세미콜론이어야합니다 – Shakka