google / guice

Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 11 and above, brought to you by Google.
https://github.com/google/guice
Apache License 2.0
12.51k stars 1.67k forks source link

Option to ignore wildcards in keys #1282

Open swankjesse opened 5 years ago

swankjesse commented 5 years ago

Using Guice with Kotlin is annoying because Kotlin inserts implied wildcards. For example, this Kotlin code:

class Jesse {
  @Inject var tacos: List<Taco>? = null
)

is equivalent to this Java code:

class Jesse {
  @Inject List<? extends Taco> tacos;
}

Note that Kotlin’s List<Taco> is equivalent to Java’s List<? extends Taco>! And this is really annoying because it’s invisible in the source code.

I claim that nobody ever wants to differentiate between types with wildcards and similar types without. Ie. nobody uses both Key<List<? extends Taco>>, Key<List<Taco>> in the same application on purpose.

I’d like to implement an opt-in feature for Guice that canonicalizes keys to strip all wildcards from their types. If I implement such a thing, is anyone interested in code reviewing? It could remove a particularly annoying stumbling block from Google’s best dependency injector.

mcculls commented 4 years ago

Hi Jesse, I don't mind providing an extra pair of eyes (although I guess you'll need someone from Google to do a formal review)

swankjesse commented 4 years ago

@mcculls PR is up!