You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Complex classes are often provided with a static factory method, used to instantiate an object of the complex class. Furthermore, it would be beneficial for the use of Singletons to support such methods.
A fairly simple method of supporting static factory methods could be achieved through a new annotation BeanFactoryMethod.
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface BeanFactoryMethod {
String[] value();
}
This annotation would accept a String-array, containing the names of the fields that would need to be provided to the method as arguments, in the correct order.
In order to process the BeanFactoryMethod, a new implementation of the BeanInitializer-interface could be provided, to properly invoke the factory method.
It is important to note that, as this process runs before a target-object has been initialized, there is no object of the target type available for use in reflection. As such, the factory method MUST be static, as the call to it will use Method#invoke(Object, Object...). As no object of the target type is available, we would be forced to pass null as the first parameter. This is only possible for static methods.
The text was updated successfully, but these errors were encountered:
Complex classes are often provided with a static factory method, used to instantiate an object of the complex class. Furthermore, it would be beneficial for the use of Singletons to support such methods.
A fairly simple method of supporting static factory methods could be achieved through a new annotation BeanFactoryMethod.
This annotation would accept a String-array, containing the names of the fields that would need to be provided to the method as arguments, in the correct order.
In order to process the BeanFactoryMethod, a new implementation of the BeanInitializer-interface could be provided, to properly invoke the factory method.
It is important to note that, as this process runs before a target-object has been initialized, there is no object of the target type available for use in reflection. As such, the factory method MUST be static, as the call to it will use Method#invoke(Object, Object...). As no object of the target type is available, we would be forced to pass null as the first parameter. This is only possible for static methods.
The text was updated successfully, but these errors were encountered: