If you need to inject a parameterized type, such as List<string>:
Class
Example {
@Inject
void setlist (list<string> List) {
...
}
}
You can use Typeliteral to create this binding. Typeliteral is a special type that can be used to represent parameterized types.
@Override public void Configure () {
bind (new Typeliteral<list<string>> () {})
. ToInstance (New Arraylist<string> ()); }
Or use the @Provides method:
@Provides list<string>
provideslistofstring () {return
new arraylist<string> ();
}
So far, the basic introduction of Google Guice usage, the above usage also applies to the Java SE, Java EE platform, in more detail can refer to the English document: http://code.google.com/p/google-guice/wiki/ Motivation, followed by the use of the Dependency injection (Roboguice) associated with the Android platform.
View a full set of articles: Http://www.bianceng.cn/OS/extra/201301/34950.htm