: http://code.google.com/p/google-guice/的Java吉斯 - 方法toProvider不适用于我从这里以下吉斯文件的参数
和我被困在toProvider
方法。当我尝试这样做:
bind(Shape.class).toProvider(ShapeProvider.class);
我得到这个错误:
The method toProvider(Provider<? extends Shape>) in the type LinkedBindingBuilder<Shape> is not applicable for the arguments (Class<ShapeProvider>)
我下面的代码:
配置类
public class Configuration extends AbstractModule{
@Override
protected void configure(){
bind(Shape.class).toProvider(ShapeProvider.class);
bind(Triangle.class).to(IsoTriangle.class);
}
ShapeProvider类
public class ShapeProvider implements Provider<Shape> {
private int length;
@Inject
public ShapeProvider(int length){
this.length = length;
}
public Shape get(){
Shape triangle = new Triangle(length);
return triangle;
}
}
Shape接口
public interface Shape {
}
三角类
public class Triangle implements Shape{
int length;
public Triangle(){
}
public Triangle(int lenght){
this.length = lenght;
}
}
难道我错过了什么或有未在文件中提到的东西吗?
更新:
提供接口:
public interface Provider<T> {
T get();
}
检查您的提供商的导入。你可能会输入错误的一个 – dhamibirendra
@dhamibirendra谢谢你的提示,即使这不是它,但这表明我做错了什么。 – Andrius