How to replace the below code using Java 8 Optionals (Functional programming)?
ClassA classA = dbService.findByA(a);
if (classA == null) {
classA = dbService.findByB(b);
}
if (classA == null) {
throw new Exception();
}
return classA;
edit:
Maybe if I will make findByA
and findByB
returning Optional will make my code cleaner using Functional programming?