There's no way to do this.
As RC noted in the comments, if you have two classes that both "@Exports
" the same interface, Guice wouldn't know which one to pick. Furthermore, consider it from the class-loading perspective:
- Explicit bindings (either linked or untargeted) work because the Module explicitly refers to every class it binds, which allows Guice to find those classes.
- JIT bindings work because they ask for the specific class they implement, which also allows Guice to find those classes.
@ImplementedBy
annotations work because once the class requested has been loaded, it points to the implementation, so Guice knows how to find that class.
If one were to write an @Exports
annotation, Guice would effectively have to have already found BClass
in order to recognize that it offers AInterface
, despite no explicit reference to BClass
anywhere. Though class-path scanning solutions exist, they have to mill through every class on the classpath, which takes some time and would be a dangerous thing for Guice to do silently. Therefore, it makes the most sense to require some kind of explicit binding for the case you're looking for.