Code: Select all
Optional c1 = ...
Optional c2 = ...
Code: Select all
void match(Contact c1, Contact c2) {...}
Meine Frage ist "Welches ist der eleganteste Weg, das in Java 8 zu machen?"
Bisher habe ich zwei Möglichkeiten gefunden:
- durch die Verwendung von isPresent
Code: Select all
if (c1.isPresent() && c2.isPresent()) { match(c1.get(), c2.get()); }
- durch die Verwendung von verschachteltem ifPresent
Code: Select all
c1.ifPresent((Contact _c1) -> { c2.ifPresent((Contact _c2) -> { match(_c1, _c2); }); });
Code: Select all
for {
contact1