public class TestMap
{
public static void main(String ... args)
{
final TestMap map = Guice.createInjector(
new AbstractModule()
{
@Override
protected void configure()
{
bindConstant()
.annotatedWith(Names.named("a"))
.to("test-1");
bindConstant()
.annotatedWith(Names.named("b"))
.to("test-2");
bindConstant()
.annotatedWith(Names.named("c"))
.to("test-3");
bindConstant()
.annotatedWith(Names.named("d"))
.to("test-4");
bindConstant()
.annotatedWith(Names.named("e"))
.to("test-5");
}
}).getInstance(TestMap.class);
System.out.println( map.get("a") );
System.out.println( map.get("b") );
System.out.println( map.get("c") );
System.out.println( map.get("d") );
System.out.println( map.get("e") );
}
private HashMap<String,String> map =
new HashMap<String,String>();
@Inject
public TestMap(
@Named("a") String a,
@Named("b") String b,
@Named("c") String c,
@Named("d") String d,
@Named("e") String e)
{
map.put("a", a);
map.put("b", b);
map.put("c", c);
map.put("d", d);
map.put("e", e);
}
public String get(final String key)
{
return map.get(key);
}
}