-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement
Milestone
Description
Andy Wilkinson opened SPR-14980 and commented
When using ObjectProvider
with constructor injection, I quite often find myself doing something like this:
public class FooConfiguration {
private final List<FooCustomizer> fooCustomizers;
public FooConfiguration(ObjectProvider<List<FooCustomizer>> fooCustomizersProvider) {
List<FooCustomizer> providedCustomizers = fooCustomizersProvider.getIfAvailable();
this.fooCustomizers = providedCustomizers == null ? Collections.emptyList()
: providedCustomizers;
}
}
I'd quite like to be able to avoid the temporary storage in providedCustomizers
and do something like this instead:
public FooConfiguration(ObjectProvider<List<FooCustomizer>> fooCustomizersProvider) {
this.fooCustomizers = fooCustomizersProvider.computeIfAbsent(() -> {
return Collections.emptyList();
});
}
Affects: 5.0 M3
Issue Links:
- Add a functional way to register a bean [SPR-14832] #19398 Add a functional way to register a bean
- Lambda-based consumption of an ObjectProvider's object when available [SPR-16001] #20550 Lambda-based consumption of an ObjectProvider's object when available
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement