Problem with Guice / Eclipse TypeLiteral

That is the question I have. I have an interface:

public interface MyInterface <AMessageTuple>{

public ConnectableObservable<AMessageTuple> getTokenConnectableObservable();
}

And I have an implementation in which I want to be a single:

public class MyImpl implements MyInterface<ImmutablePair<String, Message>> {

...
//irrelevant members omitted

@Override
public ConnectableObservable<ImmutablePair<String, Message>> getTokenConnectableObservable() {
    return tokenObservable;
}

...
}

When I try to associate an interface with an implementation in a class that extends Guice AbstractModule:

public class MyServiceModule extends AbstractModule {

    @Override
    protected void configure() {
        TypeLiteral <MyInterface<ImmutablePair<String, Message>>> t = new TypeLiteral<MyInterface<ImmutablePair<String,Message>>>() {
        };  
        bind(t).annotatedWith(Names.named("firstOne")).to(MyImpl.class).in(Singleton.class);
    }
}

bind... ligne is underlined in red (as a compilation error), and this message appears when it hangs:

bind(Key<T>)Type method AbstractModulenot applicable to arguments(TypeLiteral<MyInterface<ImmutablePair<String, Message>>>)

The odd thing is that pressing Ctr + Space recognizes that the bind (TypeLiteral) method exists ... So I'm a bit puzzled and hope someone can give me a hint about what I am missing.

: Eclipse Neon IDE, () Guice ( 4.0) DI, JDK - -7. Guice .

+4
1

, import com.google.inject.TypeLiteral;

0

Source: https://habr.com/ru/post/1674250/


All Articles