frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

createInjector should take Iterable<? extends Module> instead of Iterable<Module> #143

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
http://groups.google.com/group/google-guice/t/7813015f7a00f8a5

from   Johannes Schneider <johannes@familieschneider.info>
Hi,
com.google.inject.Guice#createInjector has the following signature:
public static Injector createInjector(Iterable<Module> modules)
Shouldn't that be changed to
public static Injector createInjector(Iterable<? extends Module> modules)

I have a list of my modules as static reference (usefull for testing
purposes).

Collections.unmodifiableList( Arrays.asList( new ApplicationModule(),
new SecurityModule(), new ScannerModule(), new InvoiceModule() ) )

But this line returns a List of AbstractModules (or List<? extends
Module>)....

Original issue reported on code.google.com by robbie.v...@gmail.com on 22 Aug 2007 at 9:50

GoogleCodeExporter commented 9 years ago
I have created a patch that fixes this problem. It also widens the generic
collections at some other locations.
The tests still run fine so I think there shouldn't be any problem

Original comment by johan...@familieschneider.info on 23 Aug 2007 at 8:38

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the patch. I think we want to be more flexible about what we accept, 
but
not so much about what we return.

Original comment by crazybob...@gmail.com on 9 Sep 2007 at 9:19

GoogleCodeExporter commented 9 years ago
I think returning a collection without a "?" is only useful, if someone wants 
to add
anything to this collection.
So in my opinion "List<? extends Foo>" is better than "List<Foo>" as return 
type if
the list is read only.

But this is just my opinion - do whatever you prefer.

Original comment by johan...@familieschneider.info on 10 Sep 2007 at 3:43