Consider the following bean definition:
RootBeanDefinition beanDefinition = (RootBeanDefinition) BeanDefinitionBuilder
.rootBeanDefinition(DocumentBuilderFactory.class).setFactoryMethod("newNSInstance").getBeanDefinition();
Compilation of the generated code fails as follows:
reference to withGenerator is ambiguous
both method withGenerator(org.springframework.util.function.ThrowingBiFunction<org.springframework.beans.factory.support.RegisteredBean,org.springframework.beans.factory.aot.AutowiredArguments,T>) in org.springframework.beans.factory.aot.BeanInstanceSupplier and method withGenerator(org.springframework.util.function.ThrowingSupplier<T>) in org.springframework.beans.factory.aot.BeanInstanceSupplier match /com/example/TestTarget__TestCode.java 21:148
incompatible types: invalid method reference
incompatible types: org.springframework.beans.factory.support.RegisteredBean cannot be converted to java.lang.String /com/example/TestTarget__TestCode.java 21:163
The reason is that DocumentBuilderFactory
has two static methods named newNSInstance
. A no-arg one and a two-args one. We have a similar arrangement for withGenerator
that can take a BiFunction
or a Supplier
.