我的代码段如下:
class MyObject{
Set<AnotherObject> mySet;
public Set<MyAnotherObject> getMySet(){
// getter code
}
}
if ( myObject.getMySet().isEmpty() ) {
return Optional.empty();
}
else {
MySecondObject mySecObj = new
MySecondObject(myObject.mySet().findFirst.get().value);
return Optional.of(mySecObj);
}
如何将其转换为Optional Map惯用方式以摆脱if-else块?