Using Spring, I can get all beans of a certain type that are currently defined using this:
@Resource
private List<Foo> allFoos;
How does Spring do this? I thought type information of generics was erased at runtime. So how does Spring know about the type Foo
of the list and only inject dependencies of the correct type?
To illustrate: I don't have a bean of type "List" that contains the other beans. Instead, Spring creates that list and adds all beans of the correct type (Foo
) to this list and then injects that list.