“未转换成与类型符合T”如果我有以下几点:泛型方法 - 警告
public interface Foo {
<T extends Foo> T getBlah();
}
public class Bar implements Foo {
public Bar getBlah() {
return this;
}
}
我得到一个警告在Eclipse关于“getBlah”类酒吧执行:
- Type safety: The return type Bar for getBlah from the type Bar needs unchecked conversion to conform to T from the type
Foo
我该如何解决这个问题?为什么我会收到警告?
感谢
你写过'getBlah'返回的类型必须扩展接口'Foo'。但是'Bar'没有,它实现了它。 – vulkanino 2012-02-21 17:03:58
'扩展'涵盖了接口实现 – Joeblackdev 2012-02-21 17:05:10
过度泛化的情况。看到Joeblackdev的评论和Alessandro Santini的回答。 – Saintali 2012-02-21 17:15:03