class Person{
Map sons;
Map getSons(){
return sons;
}
}
class Test{
public void Main(){
Person p=new Person();
Map sons=new HashMap<String,Person>();
sons.add("jack",new Person());
..... // here use guice to inject this Map object to p,how to do it?
System.out.print(new Person().getSons().count());
}
}
just like the code showed about,how to inject a existing Map object into a bean by guice ?
I suspect you want to use a TypeLiteral
You will then need to use this bind method .
Another option would be to wrap up your Map in a simpler type, a PersonAccess
, perhaps. This might be better anyway since it could hide the implementation of the lookup.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.