I think that I can become a victim of erasing styles, but I thought that I would check with others first.
I have a requirement to do something like this:
public interface FooFactory { public <T extends Bar> Foo<T> createFoo( Class<T> clazz ); }
It is completely natural to write this code. However, I am trying to implement this functionality using Spring BeanFactory , and I cannot do this.
What I would like to do is ...
public class FooFactoryImpl implements BeanFactoryAware { private BeanFactory beanFactory; public <T extends Bar> Foo<T> createFoo( Class<T> clazz ) { return beanFactory.getBean( ????????? ); } public void setBeanFactory( BeanFactory beanFactory ) { this.beanFactory = beanFactory; } }
As you can see, I put ???????? where I would like to get a bean of type Foo<T> , where T extends Bar. However, it is not possible to get an object of a class like Foo<T> , and therefore, I assume that what I'm trying to do is impossible?
Does anyone else see a way around this or an alternative way to implement what I'm trying to do?
Thanks,
Andrew
source share