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:
@@ -4,7 +4,6 @@ import org.junit.Assert.assertNotNull
|
||||
import org.junit.Test
|
||||
import org.springframework.context.support.GenericApplicationContextExtension.registerBean
|
||||
import org.springframework.beans.factory.BeanFactoryExtension.getBean
|
||||
import java.util.function.Supplier
|
||||
|
||||
class GenericApplicationContextExtensionTests {
|
||||
|
||||
@@ -27,7 +26,7 @@ class GenericApplicationContextExtensionTests {
|
||||
@Test
|
||||
fun registerBeanWithSupplier() {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean(Supplier { BeanA() })
|
||||
context.registerBean({ BeanA() })
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean(BeanA::class))
|
||||
}
|
||||
@@ -35,7 +34,7 @@ class GenericApplicationContextExtensionTests {
|
||||
@Test
|
||||
fun registerBeanWithNameAndSupplier() {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean("a", Supplier { BeanA() })
|
||||
context.registerBean("a", { BeanA() })
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean("a"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user