---- изменить ----
Вот что у меня получилось:
Код: Выделить всё
@Singleton
public final class StartupBean {
@Inject
StartupBean(SomeManager someManager) {
// nothing happening here
}
@Produces
@Named("fooObject")
public MyImplementation produceFooObject() {
return new MyImplementation();
}
@Produces
@Named("barObject")
public MyImplementation produceBarObject() {
return new MyImplementation();
}
}
// class implementing two interfaces
final class MyImplementation
extends SomethingElse
implements MyInterface, MyOtherInterface {
}
// manager class using both named instances
@Singleton
final class SomeManager {
private final MyInterface foo;
private final MyInterface bar;
@Inject
SomeManager(
@Named("fooObject") MyInterface fooObject,
@Named("barObject") MyInterface barObject) {
this.foo = fooObject;
this.bar = barObject;
// stuff happening
}
}
// class using one of the object with different type
public final class ClassA {
private final MyOtherInterface bla;
@Inject
ClassA(@Named("fooObject") MyOtherInterface fooObject) {
this.bla = fooObject;
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... same-class