{"id":4973,"date":"2014-03-30T17:19:37","date_gmt":"2014-03-30T17:19:37","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/dependency-injection-by-type-using-generics-how-does-it-work-collection-of-common-programming-errors\/"},"modified":"2014-03-30T17:19:37","modified_gmt":"2014-03-30T17:19:37","slug":"dependency-injection-by-type-using-generics-how-does-it-work-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/dependency-injection-by-type-using-generics-how-does-it-work-collection-of-common-programming-errors\/","title":{"rendered":"Dependency Injection by type using generics &#8211; how does it work?-Collection of common programming errors"},"content":{"rendered":"<p>Using Spring, I can get all beans of a certain type that are currently defined using this:<\/p>\n<pre><code>@Resource\nprivate List allFoos;\n<\/code><\/pre>\n<p>How does Spring do this? I thought type information of generics was erased at runtime. So how does Spring know about the type <code>Foo<\/code> of the list and only inject dependencies of the correct type?<\/p>\n<p>To illustrate: I don&#8217;t have a bean of type &#8220;List&#8221; that contains the other beans. Instead, Spring creates that list and adds all beans of the correct type (<code>Foo<\/code>) to this list and then injects that list.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Spring, I can get all beans of a certain type that are currently defined using this: @Resource private List 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4973","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4973"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4973\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}