- All Known Implementing Classes:
AbstractBeanFactory,BeanCreator,BeanFactoryManager
public interface BeanFactory
Interface for a factory to create instances of
WritableBean. In case you are implementing beans extending
Bean, you can simply ignore this interface and create your instances with the new operator. However,
framework code should use this interface to create instances for a given class to support the flexibility provided by
this module.- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault <B extends WritableBean>
BCreates a new instance of theWritableBeanfor the givenClass.
ATTENTION:
When creating beans from only an interface you will receive a dynamic proxy instance in JVM runtime mode.<B extends WritableBean>
Bstatic BeanFactoryget()
-
Method Details
-
create
Creates a new instance of theWritableBeanfor the givenClass.
ATTENTION:
When creating beans from only an interface you will receive a dynamic proxy instance in JVM runtime mode. In environments where dynamic proxies are not availablemmm-bean-generatorprovides a tooling for you to generate according implementations during AOT compile time (e.g. for GraalVM or TeaVM). In any case some unknown implementation will work behind the scene and therefore you should not rely on the#getClass()method of abeaninstance. Instead you should useReadableBean.getJavaClass(ReadableBean)to get the proper expected result.- Type Parameters:
B- type of theWritableBean.- Parameters:
type- theClassreflecting theWritableBean.- Returns:
- a new instance of the
WritableBeanspecified by the givenClass. Iftypeis an interface, a generated implementation is used (either as dynamic proxy or generated at compile time). Otherwise if a class is given it needs to extendBean, be non-abstract and requires a non-arg constructor.
-
create
- Type Parameters:
B- type of theWritableBean.- Parameters:
type- theClassreflecting theWritableBean.beanClass- theBeanClassthat has to correspond to theClassgiven by parametertype.- Returns:
- a new instance of the
WritableBeanspecified by the givenClass. Iftypeis an interface, a dynamic proxy implementation is generated. Otherwise if a class is given it needs to extendBean, be non-abstract and requires a non-arg constructor.
-
get
- Returns:
- the instance of
BeanFactory.
-