Avoid the need to specify Supplier in Kotlin bean registration API
Based on an idea from Mario Arias, we can avoid requiring specifying explicitly Supplier lambda type in Kotlin API by declaring the supplier parameter as "crossinline supplier: () -> T" instead of "supplier: Supplier<T>". Issue: SPR-15118
This commit is contained in:
@@ -33,16 +33,16 @@ object GenericApplicationContextExtension {
|
||||
/**
|
||||
* @see GenericApplicationContext.registerBean(Class<T>, Supplier<T>, BeanDefinitionCustomizer...)
|
||||
*/
|
||||
inline fun <reified T : Any> GenericApplicationContext.registerBean(supplier: Supplier<T>,
|
||||
vararg customizers: BeanDefinitionCustomizer) {
|
||||
registerBean(T::class.java, supplier, *customizers)
|
||||
inline fun <reified T : Any> GenericApplicationContext.registerBean(
|
||||
crossinline supplier: () -> T, vararg customizers: BeanDefinitionCustomizer) {
|
||||
registerBean(T::class.java, Supplier { supplier.invoke() }, *customizers)
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GenericApplicationContext.registerBean(String, Class<T>, Supplier<T>, BeanDefinitionCustomizer...)
|
||||
*/
|
||||
inline fun <reified T : Any> GenericApplicationContext.registerBean(name: String,
|
||||
supplier: Supplier<T>, vararg customizers: BeanDefinitionCustomizer) {
|
||||
registerBean(name, T::class.java, supplier, *customizers)
|
||||
crossinline supplier: () -> T, vararg customizers: BeanDefinitionCustomizer) {
|
||||
registerBean(name, T::class.java, Supplier { supplier.invoke() }, *customizers)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user