I am quite new to the concept of Optional. In the code posted below, i am checking the following:
if (operation_1) {
if (operation_2) {
if (operation_3) {
} else {
throw_3
}
} else {
throw_2
}
} else {
throw_1
}
but for this code, android studio, generates an error for the second orElseThrow() operation "marked below". please let me why I receive this error?how to fix it? whether or not the code i wrote below satisfies the conditions shown above.
code:
OptionalsUtils.toOptional(Room.databaseBuilder(getApplicationContext(), MovieDatabase.class, ActMain.DATA_BASE_NAME))//operation_1
.map(x->{
MovieDatabase movieRoomDb = x.fallbackToDestructiveMigration().build();
this.setInitializedBuiltMovieRoomDatabase(movieRoomDb);
return movieRoomDb;
})//operation_2
.map(y->{
SupportSQLiteOpenHelper openHelperInstance = y.getOpenHelper();
this.setSQLOpenHelperInstance(openHelperInstance);
return openHelperInstance;
})//operation_3
.orElseThrow(()-> new NullPointerException(THROW_SQL_OPEN_HELPER_NULL))//throw_3
.orElseThrow(()-> new NullPointerException(THROW_ROOM_DATABASE_PERSISTENT_BUILD_NULL))//throw_2<-cases error
.orElseThrow(()-> new NullPointerException(THROW_ROOM_DATABASE_PERSISTENT_BUILDER_NULL));//throw_1