-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Lambda-based mapping of an ObjectProvider's object when available or unique [SPR-17170] #21706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Juergen Hoeller commented For the moment, I have the impression that we got enough overloads in |
Yanming Zhou commented I think mapping is more common used than consuming. @Autowired
private ObjectProvider<OptionalBean> optionalBeanProvider;
public Optional<String> compute() {
return optionalBeanProvider.applyIfAvailable(bean -> bean.compute());
} can not write using ifAvailable because it raise compile error. @Autowired
private ObjectProvider<OptionalBean> optionalBeanProvider;
public Optional<String> compute() {
String result = null;
//Local variable result defined in an enclosing scope must be final or effectively final
optionalBeanProvider.ifAvailable(bean -> result = bean.compute());
return Optional.ofNullable(result);
} It must introduce some ugly variable holder like AutowiredAnnotationBeanPostProcessorTests.ObjectProviderInjectionBean.consumedTestBean |
Yanming Zhou commented In functional world, this is necessary trade-off, CompletableFuture has tons of methods. |
@r-sharath It's not been fixed, my proposal is accept map function beside consumer function, for now I didn't encounter such requirement in practice, I prefer to close it, but it is migrated by bot not created by me in github, I'm not able to do this, @sbrannen could you close it? |
Yanming Zhou opened SPR-17170 and commented
ObjectProvider should accept Function as argument like Consumer #20550
No further details from SPR-17170
The text was updated successfully, but these errors were encountered: