I’ve got an object ‘Foo Action’ which is of type FooProcess (interface) [null object].
I want to initialize ‘Foo Action’ as an object of a subclass [FooOne or FooTwo] of FooProcess.
Using the Spring Framework, I am able to create ArrayList FooList (a list of names of subclasses of FooProcess), now I would like to initialize FooAction as one of the subclasses. (Given a parameter selected to define which class I want it to initialize as)
All subclasses of FooProcess have a constructor which accepts a String.
My problem is specifically on this line
FooAction = component.getClass().getConstructor(f);
Full Method:
public FooProcess Load(String selected, String f) throws ClassCastException, InstantiationException, IllegalAccessException, ClassNotFoundException{
ArrayList<String> FooList = new ArrayList<String>();
final ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
provider.addIncludeFilter(new AssignableTypeFilter(FooProcess.class));
for (BeanDefinition component : provider.findCandidateComponents("org.project.foomodule.systems")) {
if(selected == component.getBeanClassName()){
FooAction = component.getClass().getConstructor(f);
} }
return FooAction;
}
Look at this, it works the same