Why do I have an error when I try to override a generic binding with Guice? (TypeLiteral)

你离开我真会死。 提交于 2019-12-05 03:39:36

You should change definition of classes which are implemented your interface.

Try this:

public class Parser1<I, O> implements IParser<I, O> {
}
public class Parser2<I, O> extends Parser1<I, O> {
}

And then you can bind your interface to class by this way:

bind(new TypeLiteral<IParser<String, String>>() {}).to(new TypeLiteral<Parser1<String, String>() {});

I'm not shure, but it looks remarkable to me that a binding to a conrete instance is used instead to a Class:

bind(new TypeLiteral>() {}).to(new TypeLiteral() {});

did you try

bind(new TypeLiteral<IParser<String, String>>() {}).to(Parser2.class});

?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!