Inherited interfaces being collected via @Autowired(required = false) in Spring -


i have 2 interfaces , b. interface b extends interface a. both of them implement method getid() identifying implementations.

public interface a{ long getid(); }  public interface b extends { long getid(); } 

i have multiple implementations , b both on software.

i have method in spring object collection of , b both mentioned below:

@autowired(required = false) public void collectaimplementations(list<a> implementations) { map<long, a> amap = new hashmap<>(implementations.size()); (a : implementations) {     amap.put(a.getid(), a);  } }  @autowired(required = false) public void collectbimplementations(list<b> implementations) { map<long, b> bmap =  new hashmap<>(implementations.size()); (b b : implementations) {    bmap.put(b.getid(), b);  } } 

the problem getting implementations of both , b in amap. there way in spring implementations in amap. 1 of hack explicit check b implementations in collectaimplementations method. there other solution?


Comments